c++ - Is Visual Studio recursive_directory_iterator.pop() broken? -


given example directory tree testing:

root          a1       a2    b       b1       b2 

i wish recursively enumerate directories, skip processing of directory completely.

according msdn documentation code following should job:

void testrecursion1() {    path directory_path("root");    recursive_directory_iterator it(directory_path);     while (it != recursive_directory_iterator())    {       if (it->path().filename() == "a")       {          it.pop();       }       else       {          ++it;       }    } } 

...it not. msdn recursive_directory_iterator.pop() states

if depth() == 0 object becomes end-of-sequence iterator.  otherwise, member function terminates scanning of current (deepest) directory , resumes @ next lower depth. 

what happens due short circuit test in pop() if 'depth == 0' nothing happens @ all, iterator neither incremented nor become end of sequence iterator , program enters infinite loop.

the issue seems semantically pop() intended shunt processing of tree next level higher current level, whereas in example wish skip processing of , continue processing @ b. first problem both these directories (a , b) exist @ same level in tree, second problem level top level of tree there no higher level @ resume processing. said still seems bug pop() fails set iterator end-of-sequence iterator causing infinite loop.

after testing reasoned if can't pop() directly, should @ least able pop() child of , achieve similar result. tested following code:

template<class tcontainer> bool begins_with(const tcontainer& input, const tcontainer& match) {    return input.size() >= match.size()       && equal(match.begin(), match.end(), input.begin()); }  void testrecursion2() {    path base_path("c:\\_home\\development\\workspaces\\scratch \\testdirectoryrecursion\\bin\\debug\\root");    recursive_directory_iterator it(base_path);     while (it != recursive_directory_iterator())    {       string relative_path =  it->path().parent_path().string().substr(base_path.string().size());       cout << relative_path << "\n";        if (begins_with(relative_path, string("\\a")))       {          it.pop();       }       else       {          cout << it->path().filename() << " depth:" << it.depth() << "\n";          ++it;       }    } } 

here test every item being processed determine whether parent root\a, , if call pop(). doesn't work. test correctly identifies whether node in tree child of , calls pop() accordingly, @ deeper level pop() still fails increment iterator, again causing infinite loop. what's more, if did work still undesirable since there no guarantee of order in sub nodes enumerated, despite test check whether particular node child of because nodes might indirect children still end processing goodly amount of anyway.

i think next course of action abandon use of recursive_directory_iterator , drive recursion manually using standard directory_iterator, seems if should able achieve need more recursive_directory_iterator i'm getting blocked @ every turn. questions are:

is recursive_directory_iterator.pop() method broken?

if not how use skip processing of directory?

isn't code want more following, using disable_recursion_pending()?

   while (it != recursive_directory_iterator())    {       if (it->path().filename() == "a")       {          it.disable_recursion_pending();       }       ++it;    } 

Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -