Question

I'm using the code below, adapted from this thread. I'm able to get the list of files in a folder, but I get segmentation fault at the end. Any idea why this is happening?
And is there a way to get std::string of the current file (complete path) in the for loop?

 boost::filesystem::path path("my_path");

 static void myfunction()
 {
     boost::filesystem::directory_iterator end_itr;
     // path is a static variable, defined somewhere else
     for(boost::filesystem::directory_iterator dir_iter(path); 
                                    dir_iter != end_itr;  ++dir_iter)
         if( boost::filesystem::is_regular_file(dir_iter->status()) )
         {
             // print


         }
  }

No correct solution

OTHER TIPS

perhaps you miss these lines:

namespace fs = boost::filesystem;
fs::directory_iterator end_itr;

and try

cout << "entry: " << dir_iter->path().filename() << "\n";
cout << "entry path: " << dir_iter->path() << "\n";

in the loop

Refs: - http://www.boost.org/doc/libs/1_49_0/libs/filesystem/v3/doc/reference.html#Class-directory_entry - http://www.boost.org/doc/libs/1_49_0/libs/filesystem/v3/doc/reference.html#class-path

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top