|
Boost Users : |
From: dizzy (dizzy_at_[hidden])
Date: 2008-04-15 08:35:51
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_at_[hidden] "Linux is obsolete" -- AST
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net