使用boost遍历文件夹
cmake配置boost(find_package):https://www.cnblogs.com/magic-428/p/9144492.html
find_package(Eigen3 REQUIRED)
### Boost
find_package(Boost REQUIRED COMPONENTS
# regex
filesystem # 我的工程中只使用了 boost 的 filesystem 功能,因此这里只有一个组件
)
if(NOT Boost_FOUND)
message("Not found Boost")
endif()
include_directories(${Boost_INCLUDE_DIRS})
message("${Boost_INCLUDE_DIRS}")
message("${Boost_LIBRARIES}")
void getFiles(const string& rootPath,vector<string> &ret,vector<string> &name){
namespace fs = boost::filesystem;
fs::path fullpath (rootPath);
fs::recursive_directory_iterator end_iter;
for(fs::recursive_directory_iterator iter(fullpath);iter!=end_iter;iter++){
try{
if (fs::is_directory( *iter ) ){
std::cout<<*iter << "is dir" << std::endl;
ret.push_back(iter->path().string());
//ScanAllFiles::scanFiles(iter->path().string(),ret);
}else{
string file = iter->path().string();
ret.push_back(iter->path().string());
fs::path filePath(file);
//cout<<filePath.stem()<<endl;
name.push_back(filePath.stem().string());
//std::cout << *iter << " is a file" << std::endl;
}
} catch ( const std::exception & ex ){
std::cerr << ex.what() << std::endl;
continue;
}
}
//return ret,name;
}