读取文件夹里的图片,能够显示出图片的文件名和个数(不仅是图片,还可以是其他文件)
来源:互联网 发布:软件开发 模型 编辑:程序博客网 时间:2024/06/05 16:28
头文件
FilePath.h
#ifndef FILE_PATH_H
#define FILE_PATH_H
#include<io.h>
#include <unordered_map>
#include <vector>
using namespace std;
class FilePath{
public:
FilePath();
~FilePath();
void getFile(string path,vector<string>& files);
int getFilesAll(string path,unordered_map<string,vector<string>>&files,int threshold=INT_MAX)
int getFilesAll(string path,vector<string>&files,int threshold=INT_MAX);
}
#endif
源文件:
FilePath.cpp
FilePath::FilePath()
{
}
FilePath::~FilePath()
{
}
void FilePath::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,",")!=&&strcmp(fileinfo.name,"..")!=0)
continue;
}
else
{
string fn(fileinfo.name);
if(fn.length()<4) continue;
fn=fn.sunstr(fn.length()-4)
if(fn==".jpg" || fn=".png" || fn== ".bmp" || fn=="jpeg")
files.push_back(p.assign(path).append("\\").append(fileinfo.name))
}
}while(_findnext(hFile,&fileinfo)==0);
_findclose(hFile);
}
}
//这个函数是实现:一个文件夹里包含多个子文件夹,子文件夹中包含多张照片
int FilePath::getFilesAll(string path,unordered_map<string ,vector<string>>&files,int threshold)
{
//文件句柄
long hFile=0;
//文件信息
struct _finddata_t fileinfo;
string p;
int res=0;
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)
{
vector<string> pf;
getFiles(path+"/"+fileinfo.name,pf);
files.insert(make_pair(fileinfo.name,pf));
res+=static_cast<int>(pf.size())>threshold:pf.size();
}
}
}while(_findnext(hFile,&fileinfo)==0);
_findclose(hFile);
}
return res;
}
//这个函数实现:一个文件夹中直接就是多张图片
int FilePath::getFilesAll(string path,vector<string>&files,int threshold )
{
//文件句柄
long hFile=0;
//文件信息
struct _finddata_t fileinfo;
string p;
if((hFile= _findfirst(p.assign(path).append("\\*").c_str(),&fileinfo))!=-1)
{
do
{
//如果是目录,迭代之
//如果不是,加入列表
iffileinfo.attrib & _A_SUBDIR)
{
if(strcmp(fileinfo.name,".")!=0&&strcmp(fileinfo.name,"..")!=0)
continue;
}
else
{
string fn(fileinfo.name);
if(fn.length()<4)
continue;
fn=fn.substr(fn.length() -4 );
if(fn==".jpg" || fn==".png" || fn== ".bmp" || fn=="jpg")
files.push_back(p.assign(path).append("\\").append(fileinfo.name));
}
}while (_findnext(hFile,&fileinfo)==0);
_findclose(hFile);
}
return files.size();
}
- 读取文件夹里的图片,能够显示出图片的文件名和个数(不仅是图片,还可以是其他文件)
- 读取两个excl文件和图片文件夹 并将其中的图片文件移动其他文件夹excl内容上传数据库
- 读取drawable文件夹的图片(根据文件名)
- C#读取文件夹里的图片
- 读取本地文件夹下的图片文件名,进行比较排序
- Matlab从其他文件夹批量读取存储图片的心得体会
- 批处理文件夹里的图片
- JAVAMAIL发送邮件正文是html格式并且显示图片还带有附件的邮件
- JAVAMAIL发送邮件正文是html格式并且显示图片还带有附件的邮件
- matlab:逐个读取文件夹里以数字命名的图片
- opencv读取一个文件夹里的所有图片
- 读取mp3里的图片
- 读取bundel里的图片
- IE6 bug:嵌入的图片是下面多出空白
- js实现图片文件校验,验证上传的文件是图片和其后缀名,大小
- 已经知道图片资源的ID号是resid。如何获取图片资源的文件名?
- 从服务器读取图片和显示图片的代码如下
- 怎样把SQL_SERVER数据库里的(类型是image)图片显示在aspx页面里的image控件里
- 【Linux】dd命令操作磁盘与镜像
- 【Linux】分区与格式化
- 【Debian】服务的建立与删除
- Opencv学习之--进度条控制视频
- 【Jsp】Ajax提交数据不刷新页面
- 读取文件夹里的图片,能够显示出图片的文件名和个数(不仅是图片,还可以是其他文件)
- 【MySql】异常:The server time zone value 'EDT' is
- 【2017/4/14】oracle10g的密码文件管理
- 【Linux】abobe flash player 安装
- 【Git】GitLab安装与配置
- vi 撤销上一步操作
- 【Git】Git客户端使用
- 详解VB调用C#类库的方法步骤
- 【Git】GitLab备份出现Error No Access Permission Denied