C + + deletes all files and directories in a file directory

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.