I want to iterate over all files in a directory matching something like somefiles*.txt.
Does boost::filesystem have something built in to
The accepted answer did not compile for me even when I used i->path().extension() instead of leaf(). What did work for me was an example from this website. Here's the code, modified, to apply a filter:
vector results;
filesystem::path filepath(fullpath_to_file);
filesystem::directory_iterator it(filepath);
filesystem::directory_iterator end;
const boost::regex filter("myfilter(capturing group)");
BOOST_FOREACH(filesystem::path const &p, make_pair(it, end))
{
if(is_regular_File(p))
{
match_results what;
if (regex_search(it->path().filename().string(), what, pidFileFilter, match_default))
{
string res = what[1];
results.push_back(res);
}
}
}
I'm using Boost version: 1.53.0.
Why we don't all just use glob() and some regex is beyond me.