c++ - Print .pdf filenames from a directory with Boost.regex -
this code:
path path = "e:\\documents\\"; boost::regex reg("(*.pdf)"); for(recursive_directory_iterator it(path); != recursive_directory_iterator(); ++it) { if(boost::regex_search(it->string(), reg)) { cout << *it << endl; } }
but , abort() error in visual studio, after running program, problem in line:
boost::regex reg("(*.pdf)");
am not declaring regex object ?
*.pdf
isn't regex, it's glob (for file matching). need
boost::regex reg("(.*\\.pdf)");
.
: matches 1 character*
: 0 or more of previous match\\
: make single\
escaping (ignore regex meaning of next character)
Comments
Post a Comment