1 //Delete all files under a file directory and delete the current folder Chrdirname = _t ("c:\\123");2 BOOL civmsvrinfo::releasedirectory (CString chrdirname)3 {4BOOL bremove =doremovedirectory (chrdirname);5 if(bremove)6 :: RemoveDirectory (chrdirname);7 Else8 returnFALSE;9 Ten returnTRUE; One A}//End of Civmsvrinfo::releasedirectory () - - //Delete all files under a file directory structure (do not delete the current folder) the BOOL civmsvrinfo::D oremovedirectory (CString chrdirname) - { -CString strDirName =Chrdirname; - + BOOL result; - HANDLE HANDLE; + win32_find_data FData; A CString strtemp; at -Handle = FindFirstFile (strDirName +"\\*.*", &fData); - - if(Handle = =Invalid_handle_value) - returnFALSE; - in Do { - if(fdata.cfilename[0] =='.' ) to Continue; + - if(Fdata.dwfileattributes = =file_attribute_directory) { the if(Strdirname[strdirname.getlength ()-1] !='\\'){ * TCHAR Cha[max_path]; $CString stra = strdirname+'\\'+Fdata.cfilename;Panax Notoginseng lstrcpy (ChA, stra); - doremovedirectory (ChA); the } + Else{ A TCHAR Chb[max_path]; theCString StrB = strDirName +Fdata.cfilename; + lstrcpy (ChB, StrB); - doremovedirectory (ChB); $ } $ -strtemp = strDirName +"\\"+Fdata.cfilename; - theSetFileAttributes (strtemp, ~file_attribute_readonly); - if(!removedirectory (strtemp))Wuyiresult =FALSE; the Else -result =TRUE; Wu } - Else About { $strtemp = strDirName +"\\"+Fdata.cfilename; -BOOL bl = setfileattributes (strtemp, ~file_attribute_readonly); - - if(!DeleteFile (strtemp)) Aresult =FALSE; + Else theresult =TRUE; - } $ the} while(FindNextFile (handle,&fData)); the the if(Handle) the FindClose (Handle); - in returnresult; the the}//End of BOOL preremovedirectory (CString DirName)
C + + deletes all files and directories in a file directory