Results 1 to 3 of 3

Thread: recursion

  1. #1

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    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
    Matt

  2. #2
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625
    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
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

  3. #3
    Lively Member
    Join Date
    Apr 2001
    Location
    Central NC
    Posts
    75
    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 "..".

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width