使用win32阅读子目录
Reading Subdirectories with win32
我正在尝试用win32函数读取一些子目录,结果是这样的。大多数事情都很顺利。我还没有完全运行这个函数,因为我还在调试它。我的问题是:我有5个实际的文件和两个子目录。当我试图获取目录中每个子目录和文件的文件名时,我会得到以下信息:"."、".."、"Subdirectory1"、"subdirectory"、"其余文件"。。。为什么我会得到一个句点,两个句点,然后是文件夹中的实际文件?
static std::vector<std::string> ReadAllFilesIntoArray(std::string contentDirPath, std::string fileType)
{
std::vector<std::string> filePaths;
std::wstring strTemp;
strTemp.assign(contentDirPath.begin(), contentDirPath.end());
HANDLE hFile = INVALID_HANDLE_VALUE;
WIN32_FIND_DATA FindFileData;
hFile = FindFirstFile(strTemp.c_str(), &FindFileData);
if (INVALID_HANDLE_VALUE != hFile)
{
int i = 0;
do{
// If it's a directory
if (FILE_ATTRIBUTE_DIRECTORY & FindFileData.dwFileAttributes)
{
// Convert wchar[260] -> std::string
char ch[260];
char DefChar = ' ';
WideCharToMultiByte(CP_ACP, 0, FindFileData.cFileName, -1, ch, 260, &DefChar, NULL);
std::string ss(ch);
std::vector<std::string> localFilePaths = ReadAllFilesIntoArray(contentDirPath.assign(contentDirPath.begin(), contentDirPath.end() - 5) + ss + "//*", fileType);
// Append the file paths found in the subdirectory to the ones found in the current directory
filePaths.insert(filePaths.begin(), localFilePaths.begin(), localFilePaths.end());
}
// Convert wchar[260] -> std::string
char ch[260];
char DefChar = ' ';
WideCharToMultiByte(CP_ACP, 0, FindFileData.cFileName, -1, ch, 260, &DefChar, NULL);
std::string tempString(ch);
// Then add to list if it's equal to the file type we are checking for
if (tempString.substr(tempString.size() - 3, tempString.size()) == fileType)
{
filePaths.resize(i + 1);
filePaths[i] = ch;
i++;
}
} while (FindNextFile(hFile, &FindFileData));
FindClose(hFile);
}
return filePaths;
}
它们是表示当前目录(.
)和父目录(..
)的特殊名称。枚举代码通常使用特殊情况检查来编写,以忽略这两个特殊值。
相关文章:
- Win32编译器选项和内存分配
- 子目录是否继承属性,例如add_definitions,include_directories和父Cmakelist.t
- 在子目录中使用target_sources()命令时用于单元测试(qtest)的项目结构
- C++win32 API创建多个类似视口的窗口
- WM_CTLCOLORSTATIC从未在WIN32应用程序中触发
- 检测win32服务创建和删除的最佳方法
- WIN32:C++,为什么在WM_CLOSE上调用Messagebox函数程序正在冻结
- 我怎样才能将所有子目录与 cmake 自动匹配
- 将 win32 hbitmap 转换为 winrt softwarebitmap
- 使用 WIN32 API (C/C++) 对特定树视图项进行着色
- Alt+Enter 在 Win32 应用中,管理大小调整和分辨率
- VSCode C++ 编译的exe感染了Win32:TrojanX-gen[Trj]
- 从预处理器获取 Windows 版本(C++ Win32)
- Issues with Win32 ReadProcessMemory API
- Win32 发送输入鼠标移动滞后并冻结
- 如何从 Win32 C++ 应用程序输出到父控制台窗口?
- C++线程:如何在一个线程仍在运行时阻止另一个线程执行 (Win32)
- 将 Win32/WinAPI 应用程序移植到 wxWidgets
- 使文件夹中的所有文件可供所有项目(子目录)访问
- 使用win32阅读子目录