Hi all! I use WTL + winapi. I need to obtain a list of files from a specified directory, including files from all subdirectories. I wrote a function, but it doesn't work correcty...
We start to search files, when we found an subdir, we set it as current direcotory, and call recursively my function for that dir. But when I'm turning back to root dir, it starts from beginnig, but doesn't continue the search, by skiping last founded subdir.
Here is the code:
Code:
void GetAllFiles(char* str, CListBox cLb)
{
HANDLE hSearch = NULL;
WIN32_FIND_DATA wfd;
SetCurrentDirectory(str);
::MessageBox(NULL, str, "CurDir", 0);
for (hSearch = FindFirstFile("*.*", &wfd); FindNextFile(hSearch, &wfd);)
{
if (strcmp(wfd.cFileName, ".") == 0) continue; /* current dir */
if (strcmp(wfd.cFileName, "..") == 0) continue; /* parent dir */
if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
strcat(str, "\\");
strcat(str, wfd.cFileName);
::MessageBox(NULL, str, "Folder:: ", 0);
GetAllFiles(str, cLb);
}
cLb.InsertString(0, wfd.cFileName);
}
if( strcmp(str, szFolderPath) )//Esli nado vyshe
{
str[ strlen(str) - strlen(wfd.cFileName) ] = '\0';
GetAllFiles(str, cLb);
}
return;
}
Thx for your answers!