I'm trying to list all folders on a system using a recursive function.
The following function works fine with Win 9x systems, but has problems on XP (not tried on NT or 2000). It gets to a protected folder named "System Volume Information" and seems to start again from the first folder it found.
Any ideas what I can do to fix this?
rgds
Andy
The following function works fine with Win 9x systems, but has problems on XP (not tried on NT or 2000). It gets to a protected folder named "System Volume Information" and seems to start again from the first folder it found.
Code:
// Usage: ListFolders( "C:\\" )
BOOL ListFolders( TCHAR *tcRoot )
{
WIN32_FIND_DATA WFD ;
HANDLE hSearch ;
TCHAR tcFolder[MAX_PATH] ;
// display directory
cout << tcRoot << endl ;
SetCurrentDirectory( tcRoot ) ;
// start search
hSearch = FindFirstFile( "*.*", &WFD ) ;
if (hSearch == INVALID_HANDLE_VALUE)
return FALSE ;
while ( FindNextFile( hSearch, &WFD ) )
{
// only if it is a directory
if ( ( ( WFD.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) )
&& ( strcmp( WFD.cFileName, ".." )
&& strcmp( WFD.cFileName, "." ) ) )
{
GetCurrentDirectory( MAX_PATH, tcFolder ) ;
// add trailing "\" if missing
if ( strncmp( &tcFolder[strlen( tcFolder )-1], "\\", 1 ) )
(void) strcat( tcFolder, "\\" ) ;
// create new path
(void) strcat( tcFolder, WFD.cFileName ) ;
// recursive call with new path
ListFolders( tcFolder ) ;
// go back one level
SetCurrentDirectory( ".." ) ;
} // end if
} // end while
// end search
(void) FindClose( hSearch ) ;
return TRUE ;
}
rgds
Andy