Delete the entire directory

xiaoxiao2021-03-06  37

Bool deleTree (CString Dirname)

{// Success: Return true; otherwise, return false

Bool result;

Result = preremovedirectory (DIRNAME)

&& removedirectory (DIRNAME);

Return Result;

}

Bool preremovedirectory (CString Dirname)

{// Success: Return true; otherwise, return false

LPTSTR LPBUFFER;

Uint usize;

CSTRING FILENAME;

Handle hheap;

Bool result;

Handle hfindfile;

Win32_find_data findfiledata;

USIZE = (GetCurrentDirectory (0, NULL)) * Sizeof (tchar);

HHEAP = getProcessheap ();

LPBuffer = (lpstr) Heapalloc (hheap, heap_zero_memory, usize);

GetCurrentDirectory (USIZE, LPBUFFER);

IF (lpbuffer! = DIRNAME) {// Adjust the current directory

SetCurrentDirectory (DIRNAME);

}

Hfindfile = findfirstfile ("*. *", & findfiledata);

CSTRING TFILE;

IF (hfindfile! = invalid_handle_value) {

Do {

Tfile = findfiledata.cfilename;

IF ((tfile == ") || (tfile =="))) Continue;

IF (FindFileData.dwFileAttributes ==

File_attribute_directory) {

IF (dirname [dirname.getlength () - 1]! = '//')

PreremoveDirectory (DirName '//' tfile);

Else

PreremoveDirectory; DirName Tfile;

IF (! RemoveDirectory (TFile))

Result = false;

Else

Result = TRUE;

}

Else

IF (! deletefile (tfile) Result = false;

Else Result = true;

}

While (FindNextFile (Hfindfile, & FindFileData);

FindClose (HFindFile);

}

Else {

SetCurrentDirectory (lpbuffer);

Return False;

}

SetCurrentDirectory (lpbuffer); // Reply to the original directory

Return Result;

}

转载请注明原文地址:https://www.9cbs.com/read-62049.html

New Post(0)