Delete all files and subdirectories in the directory and directory

xiaoxiao2021-03-06  40

VC only provides a function that deletes an empty directory, and often wants to delete a lot of subdirectories and files in practical applications. In order to achieve this, I have written the DELETEDIRECTORY function that can be implemented.

Function prototype: BOOL DELETEDIRECTORY (CHAR * DIRNAME); Return Value: Returns true when successfully delete, otherwise return false parameter DIRNAME is the directory name to be deleted, must be an absolute path name, such as "C: // Temp".

Function is defined as follows: BOOL DeleteDirectory (char * DirName) {CFileFind tempFind; char tempFileFind [200]; sprintf (tempFileFind, "% s //*.*", DirName); BOOL IsFinded = (BOOL) tempFind.FindFile (tempFileFind) While (isfinded) {isfinded = (bool) tempfind.findnextFile (); if (! TempFind.isdots ()) {Char FoundFileName [200]; strcpy (FoundFileName (). GetBuffer (200); if () {char Tempdir [200]; sprintf (tempdir, "% s //% s", dirname, findfilename; deletedirectory (Tempdir);} else {char TempFileName [200]; sprintf (TempFileName, "% s //% s", diRName, FoundFileName); deletefile (TempFileName);}}} tempfind.close (); if (! Removwdirctory) {MessageBox (0, "Delete Directory Failed!", "Warning Information ", MK_OK); Return False;} Return True;

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

New Post(0)