c++ GetJustCurrentFile 循环读取文件夹中的指定文件

编程入门 行业动态 更新时间:2024-10-26 10:35:22

c++ GetJustCurrentFile 循环读取<a href=https://www.elefans.com/category/jswz/34/1771438.html style=文件夹中的指定文件"/>

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 循环读取文件夹中的指定文件

本文发布于:2023-12-03 17:01:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1656856.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   夹中   GetJustCurrentFile

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!