Showing files in a subdirectory

stp's Avatar, Join Date: Feb 2008
stp
Light Poster
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;
}
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
You move your code into main to some other function and loop through it recursively to populate for all the directories and sub-directories.