4

「keyword.txt」に一致するディレクトリ内のすべてのファイルを繰り返し処理したい。Google でいくつかの解決策を検索したところ、これが見つかりました: マスクを使用して、Boost を使用してディレクトリ内のファイルを反復処理できますか?

後でわかったように、「leaf()」関数は置き換えられました (ソース: http://www.boost.org/doc/libs/1_41_0/libs/filesystem/doc/index.htm -> セクション「非推奨」に移動)名前と機能')

私がこれまでに得たのはこれですが、実行されていません。このなんとなくばかげた質問で申し訳ありませんが、私は多かれ少なかれC ++の初心者です。

    const std::string target_path( "F:\\data\\" );
const boost::regex my_filter( "keyword.txt" );

std::vector< std::string > all_matching_files;

boost::filesystem::directory_iterator end_itr; // Default ctor yields past-the-end
for( boost::filesystem::directory_iterator i( target_path ); i != end_itr; ++i )
{
    // Skip if not a file
    if( !boost::filesystem::is_regular_file( i->status() ) ) continue;

    boost::smatch what;

    // Skip if no match
    if( !boost::regex_match( i->path().filename(), what, my_filter ) ) continue;

    // File matches, store it
    all_matching_files.push_back( i->path().filename() );
}
4

1 に答える 1