-
I've been trying to make this function search subfolders but I can't get it to work. Heres the code.
Code:
int findfiles(char *p)
{
WIN32_FIND_DATA Find;
HANDLE hfind;
BOOL hfind2;
hfind = FindFirstFile(p, &Find);
if(hfind == INVALID_HANDLE_VALUE){
MessageBox(NULL, "Error opening file", "FindFiles", MB_OK|MB_ICONERROR);
}else
SendMessage(NULL, LB_ADDSTRING, 0, (LPARAM) Find.cFileName);
while(hfind2!=0){
hfind2 = FindNextFile(hfind, &Find);
if(GetFileAttributes(Find.cFileName)==FILE_ATTRIBUTE_DIRECTORY){
findfiles(Find.cFileName);
}
SendMessage(listbx,LB_ADDSTRING,0,(LPARAM) Find.cFileName);
}
FindClose(hfind);
return 0;
}
Thanks
-
i dont think i follow ya, where is listbx coming from in:
SendMessage(listbx,LB_ADDSTRING,0,(LPARAM) Find.cFileName);
??-- also, your recursion code is in a while loop...
i dont know windows programming, but the problem might be that it doesnt even find the sub-folders.. did you try debugging it? see if it at least "finds" the sub-folders, then if it does, i have no clue... but it looks like it should work :)
-
When you hit a sub-directory, you may want to add a "\*.* "mask to the path you pass to yourself. Moreover, you'll likely get into a recursion loop if you don't filter out entries "." and "..".