I am looking for a way to find files in a directory ( and its subdirectories) if the files matches to a pattern.
I have this code:
inline static void ScanForFiles(std::vector<string> &files,const path &inputPath,string filter="*.*",bool recursive=false)
{
typedef vector<boost::filesystem::path> vec; // store paths,
vec v; // so we can sort them later
copy(directory_iterator(inputPath), directory_iterator(), back_inserter(v));
for(int i=0; i<v.size(); i++)
{
if(IsDirectory(v[i]))
{
if(recursive)
{
ScanForDirs(files,v[i],recursive);
}
}
else
{
if(File::IsFile(v[i]))
{
files.push_back(v[i].string());
}
}
}
}
This is working, but it doesn't match pattenrs. For example I want to call this function like this:
std::vector<string> files;
ScanForFiles(files,"c:\\myImages","*.jpg",true);
and I get the list of all jpeg images in myimages and all of its subfolders.
The current code returns all images and there is no pattern match.
How can I change the above code to do so?