MFC 获取文件目录中所有文件路径
时间: 2024-02-28 20:56:38 浏览: 34
可以使用 MFC 的 CFileFind 类来遍历文件目录中的所有文件路径,示例代码如下:
```cpp
void GetAllFilePaths(const CString& strFolderPath, CStringArray& arrFilePaths)
{
CFileFind finder;
CString strWildcard = strFolderPath + _T("\\*.*");
BOOL bWorking = finder.FindFile(strWildcard);
while (bWorking)
{
bWorking = finder.FindNextFile();
if (finder.IsDots())
continue;
if (finder.IsDirectory())
{
CString strSubFolder = finder.GetFilePath();
GetAllFilePaths(strSubFolder, arrFilePaths);
}
else
{
CString strFilePath = finder.GetFilePath();
arrFilePaths.Add(strFilePath);
}
}
finder.Close();
}
```
调用该函数时,传入文件夹路径和一个 CStringArray 对象,函数会将文件夹中所有文件的路径存入 CStringArray 中。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)