#define DOWNLOAD_CLEAN_PATH _T("C:/Users/Administrator/Downloads"); //遍历删除空文件夹路径
CString CleanPath = DOWNLOAD_CLEAN_PATH;
CleanEmptyFloder(CleanPath);
BOOL CleanEmptyFloder(CString folderPath)
{
BOOL nResult;
BOOL bEmpty = TRUE;
CString tmp = folderPath;
if (tmp.Right(1) != "\\")
tmp += "\\";
tmp += "*.*";
CFileFind cFindFile;
nResult = cFindFile.FindFile(tmp);
while (nResult == TRUE)
{
nResult = cFindFile.FindNextFile();
if (cFindFile.IsDirectory() && !cFindFile.IsDots())
{
CString cFindFileTemp = cFindFile.GetFilePath();
if (!CleanEmptyFloder(cFindFileTemp))
{
bEmpty = FALSE;
}
}
else if (!cFindFile.IsDirectory() && !cFindFile.IsDots())
{
bEmpty = FALSE;
}
}
if (bEmpty)
{
return RemoveDirectory(folderPath);
}
return FALSE;
}