1
我需要递归搜索文件到一个目录及其子目录中,但我想从搜索中排除一个路径(及其文件和子目录)。std :: experimental :: filesystem :: recursive_directory_iterator跳过文件夹及其子文件夹
我正在使用std::experimental::filesystem::recursive_directory_iterator
和pop()
修饰符,但它不起作用。我错在哪里?
void search(const char* pathToSearch,const char* pathToExclude){
std::experimental::filesystem::recursive_directory_iterator iterator(pathToSearch);
for (auto& p : iterator) {
if (p.path() == std::experimental::filesystem::directory_entry(pathToExclude).path()) iterator.pop();
if (fs::is_directory(p)) continue; //exclude directory from output
else std::cout << p << std::endl;
}
}