I have a directory path, and I want to go through all its subdirectories, collecting files. By the way
namespace fs = boost::filesystem;
std::vector<fs::path> traverse_if_directory(fs::path& f) {
std::vector<fs::path> result;
if (fs::is_directory(f)) {
for (fs::recursive_directory_iterator it(f), eit; it != eit; ++it) {
if (!fs::is_directory(it->path())) {
result.push_back(it->path());
}
}
}
else {
result.push_back(f);
}
return result;
}
Unfortunately, in the middle of the passage, I stumble upon a directory that I do not have the right to look at, and the code above throws. But, obviously, in this case this is not an exception, I just have to continue by skipping this locked directory.
But how do I do this?
source
share