当前位置:网站首页>Qt读取路径下所有文件或指定类型文件(含递归、判断是否为空、创建路径)
Qt读取路径下所有文件或指定类型文件(含递归、判断是否为空、创建路径)
2022-04-23 07:15:00 【欧特_Glodon】
//遍历获取文件夹下的所有文件
void Dialog::GetAllFiles(const QString path, QFileInfoList &fileInfoList)
{
QDir dir(path);
foreach(QFileInfo info,dir.entryInfoList(QDir::NoDotAndDotDot | QDir::Dirs))
{
//qDebug()<<"dir:" << info.filePath();
GetAllFiles(info.filePath(),fileInfoList);
}
foreach(QFileInfo info,dir.entryInfoList(QDir::Files))
{
fileInfoList.append(info);
qDebug()<< "文件:" << info.filePath();
}
}
// 获取当前文件夹下的指定类型文件(非递归)
void Dialog::GetDirFiles(const QString dirPath)
{
QDir *dir = new QDir(dirPath);
// 判断路径是否存在,不存在则创建
if(!dir->exists(dirPath))
{
// 创建路径文件,可多级
dir->mkpath(dirPath);
}
// 判断文件夹内容是否为空
QFileInfoList fileInfoList;
GetAllFiles(dirPath, fileInfoList);
if(fileInfoList.size() == 0)
{
QMessageBox::information(this,"提示","文件路径下不存在任何文件!");
return;
}
// 判断文件是否存在
// QFile fileName(filePath);
// if(!fileName.exists())
// {
// return true;
// }
QStringList filter;
QList<QFileInfo> *fileInfo = new QList<QFileInfo>(dir->entryInfoList(filter));
for(int i = 0; i < fileInfo->count(); i++)
{
if(fileInfo->at(i).fileName().split(".").back() != "cpp")
{
continue;
}
qDebug()<< fileInfo->at(i).filePath();
qDebug()<< fileInfo->at(i).fileName();
}
}
// 获取当前文件夹下的所有文件夹(非递归)
void Dialog::GetAllDirs(const QString path)
{
QDir dir(path);
foreach(QFileInfo info,dir.entryInfoList(QDir::NoDotAndDotDot | QDir::Dirs))
{
qDebug()<<"path:" << info.filePath();
qDebug()<<"name:" << info.fileName();
}
}
版权声明
本文为[欧特_Glodon]所创,转载请带上原文链接,感谢
https://blog.csdn.net/m0_37251750/article/details/124300242
边栏推荐
- Kubernetes in browser and IDE | interactive learning platform killercoda
- Online yaml to XML tool
- Manipulator motion planning in 3C assembly
- Go语学习笔记 - 语言接口 | 从零开始Go语言
- js将树形结构数据转为一维数组数据
- CSV column extract column extraction
- Ignis公链的NFT生态发展:Unicorn.art的捐赠开发之路
- dmp引擎工作总结(2021,光剑)
- 总线结构概述
- Samsung, March to the west again
猜你喜欢
Brief description of CPU
干货!以点为形:可微分的泊松求解器
Principle of sentinel integrating Nacos to update data dynamically
1216_ MISRA_ C standard learning notes_ Rule requirements for control flow
数据安全问题已成隐患,看vivo如何让“用户数据”重新披甲
分布式服务治理Nacos
[programming practice / embedded competition] learning record of embedded competition (I): establishment of TCP server and web interface
一篇文章看懂变量提升(hoisting)
[appium] encountered the problem of switching the H5 page embedded in the mobile phone during the test
AAAI 2022 recruit speakers!!
随机推荐
[untitled]
dmp引擎工作总结(2021,光剑)
【无标题】
The following program deletes n consecutive words starting from the ith character from the string str
C language learning record -- use and analysis of string function (2)
[effective go Chinese translation] function
华硕笔记本电脑重装系统后不能读取usb,不能上网
Smart business card applet business card details page function implementation key code
LeetCode15. Sum of three
Rearranging log files for leetcode simple question
情境领导者-第七章、解决绩效问题
Feign source code analysis
Ribbon start process
An idea plug-in that doesn't work, but can install X
网赚APP资源下载类网站源码
C 输出一种二维数组,特点如下。
js常用数组方法
Summary of facial classics
单点登录 SSO
室内定位技术对比