c++读取文件夹所有文件路径

代码为读取文件夹内所有指定后缀文件的路径并保存与容器中,代码中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;
}

    原文作者:北方的杨先生
    原文地址: https://blog.csdn.net/Jdk_yxs/article/details/77895400
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞