c++讀取資料夾所有檔案路徑
阿新 • • 發佈:2019-01-30
程式碼為讀取資料夾內所有指定字尾檔案的路徑並儲存與容器中,程式碼中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; }