#include <io.h> #include <iostream> #include <string> #include <windows.h> #include <fstream> #include <vector> using namespace std; void getFiles(string path, vector<string>& files) { //文件句柄 intptr_t hFile = 0; //以前运行不通大多是数据类型的原因 //文件信息 struct _finddata_t fileinfo; string p; if ((hFile = _findfirst(p.assign(path).append("\*").c_str(), &fileinfo)) != -1) { do { //如果是目录,迭代之 //如果不是,加入列表 if ((fileinfo.attrib & _A_SUBDIR)) { if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0) getFiles(p.assign(path).append("\").append(fileinfo.name), files); } else { //files.push_back(p.assign(path).append("\").append(fileinfo.name)); files.push_back(fileinfo.name); } } while (_findnext(hFile, &fileinfo) == 0); _findclose(hFile); } } void main() { char * filePath = "E:\Desktop\flir\FLIR_ONE_DATA\visibal"; vector<string> files; ////获取该路径下的所有文件 getFiles(filePath, files); ofstream fileOut("Location_visibal.txt"); //目标文件写 char str[30]; int size = files.size(); for (int i = 0; i < size; i++) { fileOut << files[i].c_str() << endl; } fileOut.close(); cout << "finished" << endl; }