Reputation: 503
I want to iterate over all files in a directory matching something "keyword.txt". I searched for some solutions in google and found this: Can I use a mask to iterate files in a directory with Boost?
As i figured out later on, the "leaf()" function was replaced (source: http://www.boost.org/doc/libs/1_41_0/libs/filesystem/doc/index.htm -> goto section 'Deprecated names and features')
what i got so far is this, but it's not running. Sorry for this somehow stupid question, but im more or less a c++ beginner.
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() );
}
Upvotes: 4
Views: 4293
Reputation: 3801
Try
i->path().filename().string()
this is the equivalent for i->leaf()
in boost::filesystem 3.0
In your code:
// Skip if no match
if( !boost::regex_match( i->path().filename().string(), what, my_filter ) )
continue;
// File matches, store it
all_matching_files.push_back( i->path().filename().string() );
Upvotes: 4