代码为读取文件夹内所有指定后缀文件的路径并保存与容器中,代码中xml可换。
c++代码:
//储存文件路径的容器
std::vector< std::string > xlm_list;
//储存xml文件路径
std::string FLAGS_xml_dir = "F:\\dataset\\hlg_ann\\xml_all_shoe";
//读文件夹中所有文件
int readImageDirIfFlagEnabled()
{
// Open & read image dir if present
if (!FLAGS_xml_dir.empty()) {
std::string folderName = FLAGS_xml_dir;
if (!boost::filesystem::exists(folderName)) {
std::cout << "Folder " << folderName << " does not exist.";
return -1;
}
boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end
for (boost::filesystem::directory_iterator itr(folderName); itr != end_itr; ++itr) {
if (boost::filesystem::is_directory(itr->status())) {
// Skip directories
}
else if (itr->path().extension() == ".xml") {
// std::string filename = itr->path().string();
xlm_list.push_back(itr->path().string()); // ?????????
}
}
}
return 0;
}