boost::filesystem::recursive_directory_iterator it(inputFilePath);
fs::is_regular_file(*it) 判断是否是普通文件
it->path().extension() 获取文件后缀
it->path().string() 将整个文件路径转换为string
it->path().filename().c_str() 将文件名转换为string
//BOOST
#include <boost/algorithm/string.hpp>
#include <boost/filesystem.hpp>
#include <boost/program_options.hpp>
namespace fs = boost::filesystem;
std::string calibDir = argv[1];
std::cout << "read cloundpoint file: " << calibDir << std::endl;
bool res = get_data_filename(calibDir, data_filename);
for (int i = 0; i < data_filename.size(); i++) {
std::cout << "data_filename[" << i << "] = " << data_filename.at(i) << std::endl;
}
bool get_data_filename(std::string calibDir, std::vector<std::string> &data_filename)
{
data_filename.clear();
if (!fs::exists(calibDir) && !fs::is_directory(calibDir)) {
std::cerr << "# ERROR: Cannot find input directory " << calibDir << "." << std::endl;
return false;
}
fs::path inputFilePath(calibDir);
fs::recursive_directory_iterator it(inputFilePath);
fs::recursive_directory_iterator endit;
while (it != endit) {
if (fs::is_regular_file(*it) && it->path().extension() == ".xyz")
{
std::string file_name = it->path().string();
data_filename.push_back(file_name);
} else {
std::cout << it->path().extension() << ", not \".png\"" << std::endl;
}
it++;
}
if (data_filename.size() > 0) {
return true;
} else {
return false;
}
}