文件夹中的指定文件"/>
c++ GetJustCurrentFile 循环读取文件夹中的指定文件
c++代码片段记录
如有帮助,点赞收藏关注!
如有帮助,点赞收藏关注!
如有帮助,点赞收藏关注!
如想读取文件夹当前目录中的指定格式的文件
可使用如下的代码(此处读取 .bmp 文件)
#include <string>
#include <io.h>
#include <vector>
#include <iostream>using namespace std;static void GetJustCurrentFile(string path, vector<string>& files)
{//文件句柄 intptr_t hFile = 0;//文件信息 struct _finddata_t fileinfo;string p;if ((hFile = _findfirst(p.assign(path).append("\\*.bmp").c_str(), &fileinfo)) != -1){do{if (!(fileinfo.attrib & _A_SUBDIR)){files.push_back(p.assign(path).append("\\").append(fileinfo.name));}} while (_findnext(hFile, &fileinfo) == 0);_findclose(hFile);}
}int main()
{string imgPath = "E:\\图片";vector<string> files;files.clear();GetJustCurrentFile(imgPath , files);return 0;
}
即可获得我们想要得到的指定文件名称列表files。循环读取文件名称files[i],进行后续操作。
更多推荐
c++ GetJustCurrentFile 循环读取文件夹中的指定文件
发布评论