I am trying to display the files and folders in a directory. And if the folders have a nother folder, display those contents also, and so on.
I have this code but it isn't working the way I would like it to:
#include <Windows.h>
#include <string>
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
WIN32_FIND_DATA wfd;
HANDLE hf;
string findwhat, findwhat2;
string path = "C:";
findwhat = path + "\\*";
hf = FindFirstFile(findwhat.c_str(), &wfd);
while(hf != INVALID_HANDLE_VALUE)
{
if(wfd.cFileName[0] != '.' && (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
string found;
found = path + "\\" + wfd.cFileName;
cout<<found<<endl;
HANDLE hf2;
WIN32_FIND_DATA wfd2;
findwhat2 = path + findwhat + found + "\\";
hf2 = FindFirstFile(findwhat2.c_str(), &wfd2);
if(wfd2.cFileName[0] != '.' && (wfd2.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
cout<<"---->"<<wfd2.cFileName<<endl;
}
}
if(!FindNextFile(hf, &wfd))
{
FindClose(hf);
hf = INVALID_HANDLE_VALUE;
}
}
cin.get();
}
How do I fix it?