It is well known that the process of deleting a directory that is not empty is actually a function recursive call. It is nothing more than to call the cfilefile of the MFC and the FindNextFile or the FindNextFile function, just use the CFileFind class. The implementation process is relatively simple than the implementation of the API. By following two ways, the deletion is not empty.
// Use the CFileFind class in the MFC to delete the directory BOOL __STDCALL DELETIRECTORE (CFILEFIND TEMPFIND; char TempFileFind; char tempfilefind; cHAR TempFileFind; char tempfilefind; sprintf (tempfilefind, "% s //*.*", PSZDIR) ;
Bool isfinded = reinterpret_cast
While (isfinded) {// The reinterpret_cast mandatory type conversion here is to convert the BOOL type to BOOL type isfinded = reinterpret_cast
IF (! RemoveDirectory) // Delete the directory Return False;
Return True;}
// Use the API mode to delete the directory Bool deletedirectory (const char * pszdir) {Win32_find_data fd; char sztempfilefind [MAX_PATH] = {0}; Bool Bisfinish = FALSE
ZeromeMory (& fd, sizeof (win32_find_data));
Sprintf (sztempfilefind, "% s //*.*", pszdir);
Handle Hfind = FindfirstFile (sztempfilefind, & fd); if (hfind == invalid_handle_value) Return False;
While (! bisfinish) {bisfinish = (FindNextFile (HFIND, & FD))? false: true; if ((Fd.cfileName, ")! = 0 && (Strcmp (fd.cfilename," .. " !) = 0)) {char szFoundFileName [MAX_PATH] = {0}; strcpy (szFoundFileName, fd.cFileName); if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {char szTempDir [MAX_PATH] = {0}; sprintf (szTempDir, " % s //% s ", pszDir, szFoundFileName); deleteDirectory (szTempDir);} else {char szTempFileName [MAX_PATH] = {0}; sprintf (szTempFileName,"% s //% s ", pszDir, szFoundFileName); DeleteFile (sztempfilename);}}} findclose (HFIND);
IF (! REMOVEDIRECTORY) RETURN FALSE; RETURN TRUE;}
The above is to delete two implementations of folders that are not empty. The basic idea is not different. It is just easy to use the MFC than directly using the API. This is not!