EVC删除非空目录
//=====================================================================================================
//TITLE:
//??EVC刪除非空目錄
//AUTHOR:
//??norains
//DATE:
//??Thursday? 22-June -2006
//=====================================================================================================
??采用的是MFC,如果需要移植到SDK,只要把CString換成相應(yīng)類(lèi)型即可。
??代碼比較簡(jiǎn)單,只簡(jiǎn)單做一下解釋:
??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(szDir+"//"+fd.cFileName)==FALSE)
??????{
???????return FALSE;
??????}
?????}
??
????}while(FindNextFile(hFind,&fd));
???}
??
???//if you donot close the handle,the next step of Removing Directory would failed
???CloseHandle(hFind);
???//the root directory must be empty ,so remove it
???if(RemoveDirectory(szDir)==FALSE)
???{
????return FALSE;
???}
??
???return TRUE;
??}??????????????????????????
??????????????????????
??
??由此也可引出一個(gè)判斷目錄是否為空的代碼,也比較簡(jiǎn)單,如下:
??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;
???}
??}
//TITLE:
//??EVC刪除非空目錄
//AUTHOR:
//??norains
//DATE:
//??Thursday? 22-June -2006
//=====================================================================================================
??采用的是MFC,如果需要移植到SDK,只要把CString換成相應(yīng)類(lèi)型即可。
??代碼比較簡(jiǎn)單,只簡(jiǎn)單做一下解釋:
??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(szDir+"//"+fd.cFileName)==FALSE)
??????{
???????return FALSE;
??????}
?????}
??
????}while(FindNextFile(hFind,&fd));
???}
??
???//if you donot close the handle,the next step of Removing Directory would failed
???CloseHandle(hFind);
???//the root directory must be empty ,so remove it
???if(RemoveDirectory(szDir)==FALSE)
???{
????return FALSE;
???}
??
???return TRUE;
??}??????????????????????????
??????????????????????
??
??由此也可引出一個(gè)判斷目錄是否為空的代碼,也比較簡(jiǎn)單,如下:
??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;
???}
??}
轉(zhuǎn)載于:https://www.cnblogs.com/wodeyitian/archive/2006/06/22/2460552.html
總結(jié)
- 上一篇: Web Deployment Proje
- 下一篇: 1元递增是什么意思