So in short, in order to identify all the sub-dirs in a root directory I need to check EVERY file. I have found that each directory contains a directory with the name ".." & it lists all the directories contained in the upper/parent directory of the root directory, maybe that is a way to get a list of the sub-dirs? But is the ".." dir a feature of all windows versions?
Is there a more efficient way to obtain a list of all the sub directories within a root directory?
stack <string> getSubDirectories( string rootDir, unsigned int degree ){ // Post: Search a directory & store the absolute path of any sub- // directories (with X degree of separation) identified within // the root directory. rootDir = formatFilePath( rootDir ); WIN32_FIND_DATA dirData; HANDLE dir = openDirectory( rootDir, dirData ); // getDirectoryListing( rootDir, dirData ); stack <string> subDirs; if ( dir == NULL ) { printf( "No directory log found inside the root directory %s \n", rootDir.c_str() ); return stack <string>(); } while ( FindNextFile( dir, &dirData ) != 0 ) { if ( string(dirData.cFileName) != ".." && isDirectory( dirData.dwFileAttributes ) ) { string subDirectory = rootDir.substr(0, rootDir.length() - 1) + string( dirData.cFileName ); subDirs.push( subDirectory ); if ( degree > 1 ) { subDirs += getSubDirectories( subDirectory, degree - 1 ); } } } FindClose( dir ); return subDirs; }