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);
return0;
}
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???
Last edited by Narue; Oct 7th, 2008 at 12:47 pm. Reason: added code tags
How about you use code tags and post code that can be compiled.
There are easier ways to get file listings by using the OS list functions & _popen(). The output can be read using fread(). In windows: "dir /s/b ", in Linux: you could try "ls -R -l ".
When you read a file that's a directory, call the function again. And learn to use
CODE tags. There are at least 6 places on the site they are explained.
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.