当前位置:网站首页>Qt获取文件夹下所有文件
Qt获取文件夹下所有文件
2022-08-01 11:22:00 【九磅十五便士_】
在此记录一个常用的功能,获取文件夹下文件,或者文件夹的操作。并将该目录输出在combox控件上:
如下两个函数的作用分别是获取指定文件夹下的子文件夹,获取指定文件夹下的指定文件。注意可以通过setNameFilters获取所指定类型的文件。
//Dirs list
int QtGuiApplication::getDirs(const QString& dirName)
{
QDir* dirinfo = new QDir(dirName);
if (!dirinfo->exists()) {
delete dirinfo, dirinfo = nullptr;
return -1;
}
QStringList dirList = dirinfo->entryList(QDir::Dirs);
dirList.removeOne(".");
dirList.removeOne("..");
ui.comboBox->clear();
ui.comboBox->addItems(dirList);
delete dirinfo, dirinfo = nullptr;
return 0;
}
//Files list
int QtGuiApplication::getFiles(const QString& dirName)
{
QDir* dirinfo = new QDir(dirName);
if (!dirinfo->exists()) {
delete dirinfo, dirinfo = nullptr;
return -1;
}
dirinfo->setNameFilters(QStringList("*.png"));
QStringList fileList = dirinfo->entryList(QDir::Files);
fileList.removeOne(".");
fileList.removeOne("..");
ui.comboBox_2->clear();
ui.comboBox_2->addItems(fileList);
delete dirinfo, dirinfo = nullptr;
return 0;
}
结果如下:
边栏推荐
猜你喜欢
爱可可AI前沿推介(8.1)
mysql进阶(二十二)MySQL错误之Incorrect string value中文字符输入错误问题分析
Android 安全与防护策略
redis6 跟着b站尚硅谷学习
基于ArkUI eTS开发的坚果食谱(NutRecipes)
xss-labs靶场挑战
用户体验 | 如何度量用户体验 ?
Stone Technology builds hard-core brand power and continues to expand the global market
Drawing arrows of WPF screenshot control (5) "Imitation WeChat"
Endorsed in 2022 years inventory | product base, science and technology, guangzhou automobile group striding forward
随机推荐
R语言检验时间序列的平稳性:使用tseries包的adf.test函数实现增强的Dickey-Fuller(ADF)检验、检验时序数据是否具有均值回归特性(平稳性)、具有均值回归特性的案例
【cartographer ros】十: 延时和误差分析
重庆市大力实施智能建造,推动建筑业数字化转型,助力“建造强市”
如何获取微信视频号的地址(微信公众号的链接地址)
MFC实现交通图导航系统
【cartographer ros】10: Delay and error analysis
Basic configuration commands of cisco switches (what is the save command of Huawei switches)
分类预测 | MATLAB实现1-DCNN一维卷积神经网络分类预测
深度学习 | MATLAB实现一维卷积神经网络convolution1dLayer参数设定
Stone Technology builds hard-core brand power and continues to expand the global market
轮询和长轮询的区别
js中常用追加元素的几种方法:append,appendTo,after,before,insertAfter,insertBefore,appendChild
JWT
Promise学习(三)Promise的几个关键性问题 -- 状态改变、执行顺序与机制、多任务串联、异常穿透、中断promise链
回归预测 | MATLAB实现TPA-LSTM(时间注意力注意力机制长短期记忆神经网络)多输入单输出
Cross-domain network resource file download
redis6 跟着b站尚硅谷学习
小程序毕设作品之微信美食菜谱小程序毕业设计成品(3)后台功能
July 31, 2022 -- Take your first steps with C# -- Use C# to create readable code with conventions, spaces, and comments
Dapr 与 NestJs ,实战编写一个 Pub & Sub 装饰器