*/ -->
Author: | Thinkhy |
Date: | 2010.04.23 |
Keyword: | VC++ 清空目录 MFC |
找google代码搜索了个实用的清空目录的代码,稍加改进了一下。
BOOL CDeleteTree::EmptyDirectory(CString &sPath)
{
CFileFind finder;
CString sWildCard = sPath + "//*.*";
BOOL bFound;
BOOL bWorking = finder.FindFile(sWildCard);
bFound = bWorking;
while (bWorking)
{
bWorking = finder.FindNextFile();
if (finder.IsDots()) continue;
if (finder.IsDirectory())
{
CString s = finder.GetFilePath();
EmptyDirectory(s);
RemoveDirectory(finder.GetFilePath());
continue;
}
_tunlink( finder.GetFilePath() ); // 注意这里用的是_tunlink
}
return bFound;
}