
This is what I was going to mention in my post with . and .. special
directories. With the approach used the infinite loop should happen already
with the first occurence of .-directory, which would recurse in the same
directory and find the first item (.-dir again).
Greetings,
Ovanes
On Tue, Apr 15, 2008 at 2:35 PM, dizzy
On Tuesday 15 April 2008 14:19:51 Silvio Reis Junior wrote:
Hello friends!
Hi
I'm trying to use directory_iterator but when I try to list recursivelly an entire drive or a big directory I get an unhandled exception. I'm trying to figure out if I did something wrong but the code is very similar to the example on the boost web page.
I have used directory_iterator many times for recursive traversals, no issues so far.
Here is the code:
//------------------------------------------------------------------- VOID CFileSearch::InternalSearch( path RootDir ) { directory_iterator EndDirItr; for ( directory_iterator DirItr( RootDir ); DirItr != EndDirItr; ++DirItr ) { if ( is_regular( DirItr->status() ) ) { _tprintf( "FILE: %s\n", DirItr->path().string().c_str() ); } else if ( is_directory( DirItr->status() ) ) { _tprintf( "DIR : %s\n", DirItr->path().string().c_str() ); InternalSearch( DirItr->path() ); } } }
So you have a recursive algorithm. One thing that comes straight into my mind (especially for big structures) is the depth of the calls. Try to rewrite it iteratively and see if it still happens. Also, not sure on Windows (which you seem to be using) but on POSIX doing that is surely a problem because directory_iterator does follow symbolik links and thus one can easily create an infinite depth loop.
I also sugest that if your intentation is to recurse then just use recursive_directory_iterator directly (still pay attention to symlinks, call .no_push() on them so recursive_directory_iterator does not follow them through).
-- Mihai RUSU Email: dizzy@roedu.net "Linux is obsolete" -- AST _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users