【发布时间】:2020-04-15 16:05:55
【问题描述】:
我目前正在使用目录迭代器来读取整个目录,它做得很好,因为它读取了目录中任何子文件夹中的每个文件。
有没有办法知道它什么时候到达子文件夹的末尾,然后会回到目录的主文件夹开始下一个?
例如,如果我的目录有:
mainFOLDER>SUBFOLDER>ANOTHERSUB(this is the end)
mainFOLDER>difSUBFOLDER> so on so on
mainFOLDER> whatever
我怎么知道它何时点击“另一个子”。
if (std::filesystem::is_directory(r)) {
fs::path path = r.path();
std::string path_string = path.u8string();
if (inside == false) {
parentDir = path_string;
}
double clests = processDir(path_string,inside);
if (clests != -1) {
string newString = to_string(clests);
finishedPaths.push_back(newString + " " + parentDir);
}
}
else if (std::filesystem::is_regular_file(r)) {
fs::path path = r.path();
std::string path_string = path.u8string();
double File = processFile(path_string);
if (File != -1) {
string newString = to_string(File);
newString = newString + " " + path_string;
finishedPaths.push_back(newString);
}
}
}
【问题讨论】:
-
当你说你正在使用目录迭代器时,你是指
std::filesystem::directory_iterator吗? -
@Kevin 我更新了我的代码。谢谢
标签: c++ c++17 std std-filesystem