// aaa.cpp : 定义控制台应用程序的入口点。
//
#include "StdAfx.h"
#include <iostream>
#include <io.h>
#include <direct.h>
#include <string>
#include <vector>
#include <iomanip>
#include <ctime>
using namespace std;
void getFiles(string, vector<string>&);
int main(int argc, char **argv)
{
vector<string> files;
FILE *fp = fopen("lujing.txt","w");
getFiles("D:\\lfw\\lfw_5_POINT_112_96", files);
// print the files get
cout << files.size() << endl;
for (int j = 0; j<files.size(); ++j)
{
fprintf(fp, "%s\n", files[j]);
cout << files[j] << endl;
}
return 0;
fclose(fp);
}
void getFiles(string path, vector<string>& files)
{
//文件句柄
long 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));
}
} while (_findnext(hFile, &fileinfo) == 0);
_findclose(hFile);
}
}
在网上找了一个读取文件夹下面的所有文件到txt的code 已验证
最新推荐文章于 2020-12-16 12:11:11 发布