I have some code to find all the sub directories of a directory, but have found it can be VERY slow if there are alot of FILES in the sub directories.
Code:
void getSubDirs(char *pDir)
{
char searchdir[256];
sprintf(searchdir, "%s*", pDir);
WIN32_FIND_DATA filedata;
HANDLE hFind = FindFirstFile(searchdir, &filedata);
subDirs.add(pDir);
if(hFind!=NULL)
{
do
{
if(filedata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if(filedata.cFileName[0] != '.')
{
char directory[200];
sprintf(directory, "%s%s%s", pDir, filedata.cFileName, fSep);
getSubDirs(directory);
}
}
}while(FindNextFile(hFind, &filedata));
}
FindClose(hFind);
}
Thats the code im using. It obviously iterates through all the files, not just directories which is causing the slowdown. Is there any faster way of listing sub directories?
Example of output for getSubDirs("world\\");
world\
world\heads\
world\levels\something\
world\gani\stuff\stuff2\stuff3
world\hmmmm\