16,472
社区成员
发帖
与我相关
我的任务
分享
//
Recurse(TEXT("F:\\11"));
//
void Recurse(LPCTSTR pstr)
{
CFileFind finder;
// build a string with wildcards
CString strWildcard(pstr);
strWildcard += _T("\\*.*");
// start working for files
BOOL bWorking = finder.FindFile(strWildcard);
while (bWorking)
{
bWorking = finder.FindNextFile();
// skip . and .. files; otherwise, we'd
// recur infinitely!
if (finder.IsDots())
continue;
// if it's a directory, recursively search it
CString str = finder.GetFilePath();
if (finder.IsDirectory())
{
TRACE(_T("%s\n"), (LPCTSTR)str);
Recurse(str);
}
else
{
DeleteFile(str);
}
RemoveDirectory(str);
}
finder.Close();
}
CString strPath(lpszPath);
if(strPath.IsEmpty())
{
return strPath;
}
CString strRet;
CFileFind fFinder;
BOOL bSucc = fFinder.FindFile(strPath);
while ( bSucc )
{
bSucc = fFinder.FindNextFile();
if ( fFinder.IsDots() || fFinder.IsDirectory() )
{
continue;
}
else
{
try
{
CFile::Remove(fFinder.GetFilePath());
}
catch (...)
{
strRet = fFinder.GetFilePath();
break;
}
}
}
fFinder.Close();
return strRet;