Showing files in a subdirectory

Discussion in 'MFC' started by stp, Feb 8, 2008.

  1. stp

    stp New Member

    Joined:
    Feb 8, 2008
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    This code show the files in a directory. But how to show and the files in the subdirectories

    Code:
    
    #include <iostream>
    #include <windows.h>
    using namespace std;
    
    
    int main()
    {
    WIN32_FIND_DATA fd; 
    HANDLE hFind;
    
    
    hFind = FindFirstFile("C:\\C++\\*", &fd);
    
    
    cout<<fd.cFileName<<"\n";
    
         while(FindNextFile(hFind, &fd) != 0)
         {
         cout<<fd.cFileName<<"\n";
         }
    
    FindClose(hFind);
    
    return 0;
    }
    
    
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,336
    Likes Received:
    377
    Trophy Points:
    83
    You move your code into main to some other function and loop through it recursively to populate for all the directories and sub-directories.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice