#include <io.h> #include <string> #include <vector> #include <fstream>
void getAllFiles(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 {
// 保存文件的全路径
files.push_back(p.assign(path).append("\\").append(fileinfo.name));
} while (_findnext(hFile, &fileinfo) == 0); //寻找下一个,成功返回0,否则-1
_findclose(hFile);
}
}
void getAllFiles(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) {
files.push_back(p.assign(path).append("\\").append(fileinfo.name));
//递归搜索
getAllFiles(p.assign(path).append("\\").append(fileinfo.name), files);
}
}
else {
files.push_back(p.assign(path).append("\\").append(fileinfo.name));
}
} while (_findnext(hFile, &fileinfo) == 0); //寻找下一个,成功返回0,否则-1
_findclose(hFile);
}
}
/*
path: 指定目录
files: 保存结果
fileType: 指定的文件格式,如 .jpg
*/
void getAllFiles(string path, vector<string>& files,string fileType)
{
// 文件句柄
long hFile = 0;
// 文件信息
struct _finddata_t fileinfo;
string p;
if ((hFile = _findfirst(p.assign(path).append("\\*" + fileType).c_str(), &fileinfo)) != -1) {
do {
// 保存文件的全路径
files.push_back(p.assign(path).append("\\").append(fileinfo.name));
} while (_findnext(hFile, &fileinfo) == 0); //寻找下一个,成功返回0,否则-1
_findclose(hFile);
}
}
int main(int argc, char** argv)
{
vector<string> temp;
getAllFiles("J:\\faces\\test", temp,".jpg");
for (int i = 0; i < temp.size();++i )
{
cout << temp[i] << endl;
}
return 0;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有