/******************************************************************************************************/
//Name: GetFilePath();
//Describe:
// 获得目录下所有文件.
// 传入目标 和文件名称列表的指针:
// 返回void.
// Subject: C++
// Author :Hunk
// Add Date :2007.12.14
/******************************************************************************************************/
void GetFilePath(CString strPath, CStringList * pstrNameList)
{
CFileFind ff; //定义一个CfileFind对象
BOOL bFlag;
if (!ff.FindFile(strPath)) //打开以strPath为目标的文件查询,并检查调用是否成功
return;
while (ff.FindNextFile()) //查找下个文件
{
if (ff.IsDots())
continue;
if (ff.IsDirectory())
{
CString strTemp;
Int lie;
strTemp = ff.GetFilePath(); //取道目录的全路径
if (strTemp.Right(1) != "//")
strTemp += "//";
int lie = strPath.ReverseFind('//');
strTemp += strPath.Right(strPathName.GetLength() - lie - 1); //生成路径
GetFilePath(strTemp, pstrNameList); //递归调用函数
}
else
pstrNameList->AddTail(ff.GetFilePath()); //加入文件列表
}
if (!ff.IsDots())
{
if (ff.IsDirectory())
{
CString strTemp;
strTemp = ff.GetFilePath();
if (strTemp.Right(1) != "//")
strTemp += "//";
strTemp += GetFileName(strPath);
GetFilePath(strTemp, pstrNameList);
}
else
pstrNameList->AddTail(ff.GetFilePath());
}
ff.Close();
}
这是一个C++函数,用于获取指定目录及其子目录下的所有文件路径。通过CFileFind对象实现递归查找,将文件路径添加到提供的字符串列表中。
3867

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



