Yes, while iterating over directories, you can test for the names on your exclusion list and use the no_push()
member of the recursive iterator to prevent it from going into such a directory, something like:
void selective_search( const path &search_here, const std::string &exclude_this_directory)
{
using namespace boost::filesystem;
recursive_directory_iterator dir( search_here), end;
while (dir != end)
{
// make sure we don't recurse into certain directories
// note: maybe check for is_directory() here as well...
if (dir->path().filename() == exclude_this_directory)
{
dir.no_push(); // don't recurse into this directory.
}
// do other stuff here.
++dir;
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…