Iterating files with boost :: filesystem 3.0

I want to iterate over all the files in the directory matching "keyword.txt". I searched some google solutions and found this: Can I use a mask to iterate files in a directory with Boost?

As I understood later, 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 Functions " )

what I got so far, but it does not work. Sorry for this somehow silly question, but I'm more or less starting 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
source share
1 answer

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() ); 
+3
source

Source: https://habr.com/ru/post/1500591/


All Articles