boost::filesystem::directory_ite
2017-09-30 本文已影响0人
潇湘雨TF
如下代码是用来获取src_dir的当前目录TopDirectoryOnly或者及其子目录AllDirectory下,满足后缀extension的文件。release下正常,debug下出现 Run-Time Check Failure #2 - Stack around the variable ‘xxx stat’ was corrupted.
解决方法:
使用boost_filesystem-vc100-mt-gd-1_49.lib 而不能用boost_filesystem-vc100-mt-gd-1_47.lib,PCL 1.6.0中两个都有。
void FileSystemHelper::get_directory_files(std::vector<std::string> &files_vec,
const std::string &src_dir,
const std::string extension/* = ".txt"*/,
search_option_t search_option /*= TopDirectoryOnly*/)
{
boost::filesystem::path src_path(src_dir.c_str(), boost::filesystem::native);
if(!boost::filesystem::exists(src_path)){
return;
}
typedef boost::filesystem::directory_iterator d_iterator;
if(boost::filesystem::is_directory(src_path)){
d_iterator tmp_dir_end;
d_iterator tmp_dir_iter(src_path);
for(; tmp_dir_iter != tmp_dir_end; ++tmp_dir_iter){
if(boost::filesystem::is_directory(*tmp_dir_iter)){
if(AllDirectories == search_option){
get_directory_files(files_vec, tmp_dir_iter->path().string(), extension, search_option);
}
}else if(boost::filesystem::is_regular_file(*tmp_dir_iter)){
if(0 == extension.compare(".")){
files_vec.push_back(tmp_dir_iter->path().string());
}else{
if(is_file_end_with(tmp_dir_iter->path().string(), extension)){
files_vec.push_back(tmp_dir_iter->path().string());
}
}
}
}
}else{
if(is_file_end_with(src_dir, extension)){
files_vec.push_back(src_dir);
}
}
}