vc如何获取文件夹中文件个数

来源:百度知道 编辑:UC知道 时间:2024/06/30 22:53:41

递归获取本文件夹(包括子文件夹)中的文件:

int CountDirectory(CString path)
{
int count = 0;
CFileFind finder;
BOOL working = finder.FindFile(path + "\\*.*");
while (working)
{
working = finder.FindNextFile();
if (finder.IsDots())
continue;
if (finder.IsDirectory())
count += CountDirectory(finder.GetFilePath());
else
count++;
}
return count;
}

只获取本文件夹中的文件:

int CountDirectory(CString path)
{
int count = 0;
CFileFind finder;
BOOL working = finder.FindFile(path + "\\*.*");
while (working)
{
working = finder.FindNextFile();
if (finder.IsDots())
continue;
if (!finder.IsDirectory())
count++;
}
return count;
}

int nSum = 0;
bool FindFile(wchar_t* pwcDirectoryName)
{
CFileFind FileFind;
CString strTemp;
strTemp.Format(_T