Aug 13, 2012 at 6:29am UTC
Hello every body,
I was trying to make a function that will print all directories and subdirectories contained in them but i failed. I need help on how to call that recursion. I am using "dirent.h"
Thanks.
Aug 13, 2012 at 8:21am UTC
Try system("dir" )
Last edited on Aug 13, 2012 at 8:21am UTC
Aug 17, 2012 at 7:59am UTC
Woooow, i hv found the answer, after breaking my head for a long time. The problem i had is to find the path to be called in a recursive function.
This is that i used to do before, only function:
void show_dirs(const char* path)
{ DIR *pdir = opendir(path);
struct dirent *pent;
while (pent = readdir(pdir) )
{cout<<pent->d_name;
cout<<endl;
string nextpath = "";
strcat(nextpath, path);
strcat(nextpath, "/");
strcat(nextpath, pent->d_name);
pdir = opendir(nextpath);
while (pent = readdir(pdir) )
{ show_dirs(nextpath);
}
}
}