// Find_Filename.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//功能:扫描特定目录下的所有件名,并返回和保存文件名
#include <io.h>
#include <string>
#include <vector>
#include <iostream>
#include <fstream>
using namespace std;
//获取特定格式的文件名
void getAllFiles(string path, vector<string>& files, vector<string>& filename, string format)
{
// long hFile = 0; //32位
intptr_t hFile = 0;//文件句柄 64位下long 改为 intptr_t
struct _finddata_t fileinfo;//文件信息
string p;
if ((hFile = _findfirst(p.assign(path).append("\\*" + format).c_str(), &fileinfo)) != -1) //文件存在
{
do
{
if ((fileinfo.attrib & _A_SUBDIR))//判断是否为文件夹
{
if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)//文件夹名中不含"."和".."
{
files.push_back(p.assign(path).append("\\").append(fileinfo.name)); //保存文件夹名
getAllFiles(p.assign(path).append("\\").append(fileinfo.name), files, filename, format); //递归遍历文件夹
}
}
else
{
files.push_back(p.assign(path).append("\\").append(fileinfo.name));//如果不是文件夹,储存文件名
filename.push_back(fileinfo.name);
}
} while (_findnext(hFile, &fileinfo) == 0);
_findclose(hFile);
}
}
int main()
{
string filePath = "E:\\opencv_project\\contrib343\\build\\install\\x64\\vc15\\lib";
vector<string> files;
vector<string> filename;
string format = ".lib"; //查找文件的格式
getAllFiles(filePath, files, filename, format);
int size = files.size();
for (int i = 0; i < size; i++)
{
//cout << files[i] << endl;
}
int size1 = filename.size();
ofstream debug("debug.txt", ios::trunc);
ofstream release("release.txt", ios::trunc);
for (int j = 0; j < size; j++)
{
string Filename1 = filename[j];
if (Filename1[Filename1.find_last_of('.') - 1] == 'd')
{
debug << filename[j] << "\n";
cout << "debug lib :" << filename[j] << " was stored! " << endl;
}
else if (Filename1[Filename1.find_last_of('.') - 1] != 'd')
{
release << filename[j] << "\n";
cout << "release lib :" << filename[j] << " was stored! " << endl;
}
}
debug.close();
release.close();
system("pause");
return 0;
}