I'm having trouble implementing the top answer here: How to get list of files with a specific extension in a given folder
I am attempting to get all of the ".vol" files in the directory argv[2] and do some batch processing with each file that I find. I want to pass each file to the ParseFile function which takes a string as an argument.
// return the filenames of all files that have the specified extension
// in the specified directory and all subdirectories
vector<string> get_all(const boost::filesystem::path& root, const string& ext, vector<boost::filesystem::path>& ret){
if(!boost::filesystem::exists(root) || !boost::filesystem::is_directory(root)) return vector<string>();
boost::filesystem::recursive_directory_iterator it(root);
boost::filesystem::recursive_directory_iterator endit;
while(it != endit)
{
if(boost::filesystem::is_regular_file(*it) && it->path().extension() == ext) ret.push_back(it->path().filename());
++it;
cout << *it << endl;
return *ret; // errors here
}
}
... main function
if (batch) {
vector<boost::filesystem::path> retVec;
vector<boost::filesystem::path> volumeVec = get_all(boost::filesystem::path(string(argv[2])), string(".vol"), retVec);
// convert volume files in volumeVec to strings and pass to ParseFile
ParseFile(volumeFileStrings);
}
I am having trouble with the get_all function and how to return the vector correctly.