#include <afx.h>
void DeleteFolder(LPCTSTR strPath)
{
HANDLE hFile;
WIN32_FIND_DATA fndInfo;
CString strPathName,strSubFileName;
strPathName.Format(_T("%s\\*.*"), strPath);//wildcard 通配符
hFile=FindFirstFile(strPathName.GetBuffer(),&fndInfo);
do{
if(INVALID_HANDLE_VALUE == hFile)
{
return;
}
if('.' == fndInfo.cFileName[0])
{
continue;
}
strSubFileName.Format(_T("%s\\%s"),strPath,fndInfo.cFileName);
if(fndInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
DeleteFolder(strSubFileName.GetBuffer());
RemoveDirectory(strSubFileName.GetBuffer());
}
else
{
DeleteFile(strSubFileName);
}
}while(FindNextFile(hFile, &fndInfo) != 0);
FindClose(hFile);
RemoveDirectory(strPath);
}
int main()
{
DeleteFolder(_T("e:\\0720"));
return 0;
}
windows删除目录
最新推荐文章于 2020-10-07 23:08:46 发布