15,978
社区成员
发帖
与我相关
我的任务
分享
if(finder.IsDirectory())
{
IsHaveTxt(finder.GetFilePath();
}
改为:
if(finder.IsDirectory())
{
if(IsHaveTxt(finder.GetFilePath())
{
//不用再找了,关闭
finder.Close();
return true;
}
}
bool IsHaveTxt(CString strFolder)
{
CFileFind finder;
// build a string with wildcards
CString strWildcard(strFolder);
strWildcard += _T("\\*.*");
// start working for files
BOOL bWorking = finder.FindFile(strWildcard);
bool bRet=false;
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
if (finder.IsDirectory())
{
bRet= IsHaveTxt(finder.GetFilePath());
}
else
{
CString strTemp = finder.GetFileName();
int nPos = strTemp.ReverseFind('.');
strTemp = strTemp.Mid(nPos+1);
strTemp.MakeUpper();
if (strTemp==_T("TXT"))
{
finder.Close();
return true;
}
}
}
finder.Close();
return bRet;
}