I want to get a list of files in a folder, if there are any subfolders inside, I want the list of files within these subfolders, too.
I have read the question
How can I get the list of files in a directory using C or C++?
but it didn't help me solve all the problem.
All I want is a function like this:
vector<string> fileList;
//return the number of files within a folder.
// @ dir: the folder directory
// @ list: the output list of files
// @ filetype: could be multiple similar types
int getFileListFrom(const string & dir, vector<string>:: list,
const string & filetype);
int getFileListFrom(const string & dir, vector<string>:: list,
const vector<string> & filetypes);
I hope this function can be used as follows (hypothetically):
//Example1
fileNum1 = getFileListFrom("C:\\Program Files(x69)\\PornoX", list1, "avi");
//Example2
fileNum2 = getFileListFrom("D:\\myWorkspace\\Documentations\\", list2,
vector<string>("doc","docx","pdf","txt"));
I'm using Windows x86 system, so don't worry about cross-platform issue. Also, if any 3rd-part packages are necessary, please provide download links and documentations.
Any help will be deeply appreciated!