From: Martin (adrianm_at_[hidden])
Date: 2004-04-26 03:22:14
I have used the filesystem library for some time now and noticed that there is
no portable way of iterating over files in a directory that matches a pattern.
In my applications I often need to find all files in a directory that
matches "*.txt" or "input.*".
I think it would be a good idea to add another constructor to the
directory_iterator that support some primitive wilcards. The support could be
limited to "*" at the end or followed by a "."
(e.g. "*", "a*.*", "*.txt", "a.*")
for (path::directory_iterator itr = directory_iterator(path, "*.txt"); itr !=
I assume this limited wildcard support could easily be ported to most
Another small improvement that would make the directory_iterator easier to use
is to somehow allow it to only list directories or files. In the current
implementation you need to create a temporary to use an algorithm on all files
in a directory (or use some lambda if construct).
std::for_each(tmp.begin(), tmp.end(), func);
instead of just
std::for_each(directory_iterator(dir, files_only), directory_iterator(), func);
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk