当前位置:网站首页>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
边栏推荐
- Thinkphp6 + JWT realizes login verification
- CSV Column Extract列提取
- 1216_MISRA_C规范学习笔记_控制流的规则要求
- Ribbon start process
- 一款拥有漂亮外表的Typecho简洁主题_Scarfskin 源码下载
- 3C装配中的机械臂运动规划
- [effective go Chinese translation] function
- LeetCode简单题之统计字符串中的元音子字符串
- 简述CPU
- 1216_ MISRA_ C standard learning notes_ Rule requirements for control flow
猜你喜欢
CSV Column Extract列提取
Online yaml to XML tool
干货!以点为形:可微分的泊松求解器
Draw a circle quickly in MATLAB (the one that can be drawn directly given the coordinates and radius of the center of the circle)
1216_ MISRA_ C standard learning notes_ Rule requirements for control flow
[programming practice / embedded competition] learning record of embedded competition (II): picture streaming based on TCP
nn.Module类的讲解
如何在SQL Server中导入excel数据,2019版
Briefly describe the hierarchical strategy of memory
Data security has become a hidden danger. Let's see how vivo can make "user data" armor again
随机推荐
每周leetcode - 06 数组专题 7~739~50~offer 62~26~189~9
高精度焊接机械臂定位
【Appium】测试时遇到手机内嵌H5页面的切换问题
ApplicationReadyEvent的使用
Convert object to URL
将实例化对象的方法 给新的对象用
室内定位技术对比
编译原理题-带答案
clang 如何产生汇编文件
Kubernetes in browser and IDE | interactive learning platform killercoda
简述存储器的分级策略
欧圣电气深交所上市:市值52亿 陆为东父女为美国籍
Distributed service governance Nacos
NIH降血脂指南《your guide to lowering your Cholesterol with TLC》笔记(持续更新中)
PHP generates short links: convert numbers to letters and letters to numbers
网赚APP资源下载类网站源码
3C装配中的机械臂运动规划
AAAI 2022 recruit speakers!!
Fibula dynamic programming
Move layout (Flex layout, viewport label)