Windows限定ですが、find_file_rangeを使うと簡単に特定のディレクトリ下にあるファイルの一覧を取得できます。
#include <cstdio> #include <boost/range/algorithm/for_each.hpp> #include <boost/bind.hpp> #include <windows.h> #include "find_file.hpp" int main() { find_file::find_file_range ffrng("*.*"); boost::for_each(ffrng, boost::bind<int>(&std::printf, "%s\r\n", boost::bind(&WIN32_FIND_DATA::cFileName, _1))); }
find_file_rangeのコンストラクタはFindFirstFileの第一引数なので、"*.cpp"とすると拡張子がcppのファイルだけを取得できます。その他の条件を指定するならfilterが使えます。
// #include <boost/lambda/lambda.hpp> // #include <boost/range/adaptor/filtered.hpp> namespace bll = boost::lambda; using namespace boost::adaptors; // ディレクトリだけ出力 boost::for_each(ffrng | filtered((&bll::_1 ->* &WIN32_FIND_DATA::dwFileAttributes) & FILE_ATTRIBUTE_DIRECTORY), boost::bind<int>(&std::printf, "%s\r\n", boost::bind(&WIN32_FIND_DATA::cFileName, _1)));