Farida Gayfutdinova
Farida Gayfutdinova

Reputation: 21

Do I need to close directories if I use using namespace boost::filesystem::recursive_directory_iterator or not?

For example I have this code. I use recursive_directory_iterator. Do I need to close directories in this cycle or boost do it automatically?

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;
    }
 }

Upvotes: 1

Views: 122

Answers (1)

VLL
VLL

Reputation: 10165

Closing manually is not necessary. Directory iterator closes each entry when it is no longer needed.

Upvotes: 1

Related Questions