void TraversFile(CString csPath)
{
CString csPrePath = csPath;
CString csNextPath = csPath;
CFileFind ff;
csPath += _T("*.*");//遍历这一级全部的目录
int nResult = ff.FindFile(csPath);
while(nResult)
{
nResult = ff.FindNextFileW();
if(ff.IsDirectory() && !ff.IsDots())//递归遍历
{
wcout << (LPCTSTR)ff.GetFilePath() << endl;
csNextPath += ff.GetFileName();
csNextPath += _T("\\");
TraversFile(csNextPath);
}
csNextPath = csPrePath;
}
}很简单,没什么好说的~
本文介绍了一个简单的C++函数,用于遍历指定路径下的所有文件和子目录,通过添加通配符'*.*'来匹配所有文件,并递归地调用自身来遍历每个子目录。

1420

被折叠的 条评论
为什么被折叠?



