void RecursiveFindFile(CString strRootPath)
{
/*
主要是CFileFind类的使用。
重要方法;
FindFile()
FindNextFile()
*/
// strRootPath 为目录名;
CFileFind finder;
CString FilePath;
if ( strRootPath.Right(1) != "/" )
strRootPath += "/";
strRootPath += "*.*";
BOOL res = finder.FindFile(strRootPath); // 开始遍历root文件夹下有没有文件或文件夹;
while ( res ) // res为1,表示仍有nextFile;
{
res = finder.FindNextFile();
FilePath = finder.GetFilePath();
if ( finder.IsDots() ) continue; // 如果文件为“.”或“..”,则跳过本次循环;
if ( finder.IsDirectory() ) // 找到的是文件夹;
{
RecursiveFindFile(FilePath); // 递归;
}
else if ( !finder.IsDirectory() ) // 找到的是文件;
{
AfxMessageBox(finder.GetFileName()); // 显示文件名
}
}
}
MFC: 遍历文件夹
最新推荐文章于 2023-11-18 12:43:47 发布