The following program lists the files in the current directory whose name matches the regular expression filename_[0-5][34]:
#include <boost/filesystem.hpp>
#include <boost/regex.hpp> // also functional,iostream,iterator,string
namespace bfs = boost::filesystem;
struct match : public std::unary_function<bfs::directory_entry,bool> {
bool operator()(const bfs::directory_entry& d) const {
const std::string pat("filename_[0-5][34]");
std::string fn(d.filename());
return boost::regex_match(fn.begin(), fn.end(), boost::regex(pat));
}
};
int main(int argc, char* argv[])
{
transform_if(bfs::directory_iterator("."), bfs::directory_iterator(),
std::ostream_iterator<std::string>(std::cout, "\n"),
match(),
mem_fun_ref(&bfs::directory_entry::filename));
return 0;
}
For brevity, I omitted the definition transform_if(). This is not a standard feature, but it should be easy to implement.