C++:在Windows中浏览名称中带有点的文件名

C++: browse filenames in Windows which have dots inside the names

本文关键字:文件名 Windows 浏览 C++      更新时间:2023-10-16

让我们以以下文件名为例:abc.def.txt.我正在使用FindFirstFileA()FindNextFileA()来浏览目录。该函数如下所示:

std::vector<std::string>* readDir(std::string pattern) {
auto v = new std::vector<std::string>;
pattern.append("\*");
WIN32_FIND_DATAA data;
HANDLE hFind;
if ((hFind = FindFirstFileA(pattern.c_str(), &data)) != INVALID_HANDLE_VALUE) {
do {
v->push_back(data.cFileName);
} while (FindNextFileA(hFind, &data) != 0);
FindClose(hFind);
}
return v;
}

问题是前面提到的文件名将显示为abcdef.txtabc def.txt.我该怎么做才能获取带有点的文件名称?

看起来您正在查找旧的 8.3 名称。你想要FindFirstFileExFindExInfoBasic级.这将忽略 8.3 名称。