EVC delete non-empty catalog

xiaoxiao2021-04-06  280

/ / =========================================================================================================================================================================================== ============================================================================================================================================================================================================= ===

// Title:

// EVC deletes a non-empty directory

// Author:

// Norains

// Date:

// thursday 22-june -2006

/ / =========================================================================================================================================================================================== ============================================================================================================================================================================================================= ===

The MFC is used, and if you need to be ported to SDK, just replace the CString to the corresponding type.

The code is relatively simple, just simply explain:

Bool DeletedIRectory (const cstring szdir)

{

Cstring szfinddir = szdir;

IF (szfinddir.right (1)! = "//")

{

SZFINDDIR = "//";

}

SZFINDDIR = "*. *";

WIN32_FIND_DATA FD;

Handle hfind;

Hfind = FindfirstFile (Szfinddir, & FD);

IF (HFIND! = INVALID_HANDLE_VALUE)

{

Do {

IF (fd.dwfileAttributes == file_attribute_directory)

{

// IT Must Be Directory, Get Into

DELETEDIRECTORY (SZDIR "

//" fd.cfilename;

}

Else

{

// IT is file, delete it

IF (deletefile "

// " fd.cfilename) == false) {

Return False;

}

}

} while (FindnextFile (Hfind, & FD));

}

// if you donot Close The Handle, The Next Step of Removing Directory Would Faled

CloseHandle (HFIND);

// The root directory Must Be Empty, So Remove IT

RemoveDirectory (SZDIR) == FALSE

{

Return False;

}

Return True;

}

This can also be taken out of a code that judges whether or not the directory is, it is relatively simple, as follows:

Bool IsdiRempty (Const Cstring Szdir)

{

Cstring szfinddir = szdir;

IF (szfinddir.right (1)! = "//")

{

SZFINDDIR = "//";

}

SZFINDDIR = "*. *";

WIN32_FIND_DATA FD;

Handle hfind;

Hfind = FindfirstFile (Szfinddir, & FD);

IF (HFIND! = INVALID_HANDLE_VALUE)

{

Return False;

}

Else

{

// IT IS EMPTY

Return True;

}

}

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

New Post(0)