I'm trying to recursively search through directories and pull out any files or subdirectories.
This is the code I have:
int readDir(string directory, vector<string> &fileList)
//directory is the name of a direcotry
//fileList is an empty vector
DIR *dir;
struct dirent *ent;
if((dir = opendir(director.c_str()) == NULL){
cout<<"Invalid Directory"<<endl;
exit(1);
}
while((ent = readdir(dir)) != NULL){
fileList.push_back(string(ent->d_name));
}
closedir(dir);
return 0;
}
As of right now, it can read in a directory and list the files and subdirectories. I want it to now go through each subdirectory and get the files inside. Does anyone know how to go about making this a recursive function???