如何获得一个指定目录中的文件个数?以及制定的文件后缀的个数
int count;
int CGetFileCountDlg::GetFileCount(CString szPath)
{
count = 0;
Recurse(szPath);
return count;
}
void CGetFileCountDlg::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();
if (finder.IsDots()) //判断是否是文件
continue;
if(!finder.IsDirectory())
{
count ++;
}
// if its a directory, recursively search it
if (finder.IsDirectory()) //判断是否是文件夹 //路径
{
CString str = finder.GetFilePath();
Recurse(str);
}
}
finder.Close();
}
count 就是目录下文件的个数