遍历文件夹下所有文件
MFC 的 CFileFind类 有个 FindFile 和 FindNextFile 函数,它既不会搜索兄弟目录, 不会搜索子目录的,但是提供了一个判断函数 CFileFind::IsDirectory(), 判断该文件夹下某个文件路径是不是目录,如果是目录的话,还得递归遍历。
CFileFind 查找文件夹下的文件时是需要全路径的。
void CXXXDlg::SearchFiles(CString strMusicFolder)
{
CFileFind ff;
strMusicFolder += _T("\\");
strMusicFolder += _T("*.*");
BOOL res = ff.FindFile(strMusicFolder);
while (res)
{
res = ff.FindNextFile();
if (!ff.IsDirectory() && !ff.IsDots())
{
afxMessageBox(ff.GetFilePath());
}
}
ff.Close();
}
遍历文件夹下指定格式文件
已知文件夹路径“D:\temp” ,要读取里面多个”.DAT”类型文件,并保存路径到strPath[ ] 数组中。