VS2015获取某个特定文件夹下的所有XML文件/TXT文件

测试案例

#include<iostream>
#include<string>
#include<vector>
#include<io.h>
#include<tinystr.h>
#include<tinyxml.h>

using namespace std;

//box参数结构体
struct BoxSize
{
	int xMin;
	int yMin;
	int xMax;
	int yMax;
};

int main(int argc, char* argv[]) {	
	string m_strXmlPath = "E:\\eye_data\\labels";
	long hFile = 0;
	struct _finddata_t fileInfo;
	string pathName, exdName;
	// \\* 代表要遍历所有的类型
	if ((hFile = _findfirst(pathName.assign(m_strXmlPath).append("\\*").c_str(), &fileInfo)) == -1)
	{
		return -1;
	}
	do
	{
		//判断文件的属性是文件夹还是文件
		//cout << fileInfo.name << (fileInfo.attrib&_A_SUBDIR ? "[folder]" : "[file]") << endl;
		if (fileInfo.attrib&_A_SUBDIR)
			continue;
		TiXmlDocument Document;
		//读取xml文件中的参数值
		string path = m_strXmlPath + "\\" + (string)fileInfo.name;
		//cout << path << endl;
		if (!Document.LoadFile(path.c_str()))
		{
			cout << "无法加载xml文件!" << endl;
			return -1;
		}
		else
			cout << "success" << endl;
		TiXmlElement* RootElement = Document.RootElement();		//根目录
		TiXmlElement* NextElement = RootElement->FirstChildElement();		//根目录下的第一个节点层
		while (NextElement != NULL)		//判断有没有读完
		{
			if (NextElement->ValueTStr() == "filename")		//读到filename节点
			{
				cout << NextElement->GetText() << endl;
				break;
			}
			NextElement = NextElement->NextSiblingElement();
		}
	} while (_findnext(hFile, &fileInfo) == 0);
	_findclose(hFile);
	return 0;
}

运行结果

VS2015获取某个特定文件夹下的所有XML文件/TXT文件