Help with recursive functions

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.
Try system("dir")
Last edited on
Show what you've got.
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);
}

}
}
Topic archived. No new replies allowed.