当前位置:网站首页>QT reads all files under the path or files of the specified type (including recursion, judging whether it is empty and creating the path)
QT reads all files under the path or files of the specified type (including recursion, judging whether it is empty and creating the path)
2022-04-23 08:19:00 【Ott_ Glodon】
// Traverse to get all files under the folder
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()<< " file :" << info.filePath();
}
}
// Get the file of the specified type under the current folder ( Non recursive )
void Dialog::GetDirFiles(const QString dirPath)
{
QDir *dir = new QDir(dirPath);
// Determine if the path exists , Create if it does not exist
if(!dir->exists(dirPath))
{
// Create path file , It can be multi-level
dir->mkpath(dirPath);
}
// Determine whether the folder content is empty
QFileInfoList fileInfoList;
GetAllFiles(dirPath, fileInfoList);
if(fileInfoList.size() == 0)
{
QMessageBox::information(this," Tips "," There are no files in the file path !");
return;
}
// Judge whether the file exists
// 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();
}
}
// Get all folders under the current folder ( Non recursive )
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();
}
}
版权声明
本文为[Ott_ Glodon]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230714487330.html
边栏推荐
- CGM优化血糖监测管理——移宇科技亮相四川省国际医学交流促进会
- 室内定位技术对比
- Ubuntu安装Mysql并查询平均成绩
- LeetCode簡單題之計算字符串的數字和
- Detailed explanation of ansible automatic operation and maintenance (I) installation and deployment, parameter use, list management, configuration file parameters and user level ansible operating envi
- [go]常见的并发模型[泛型版]
- Search the complete navigation program source code
- 谈谈那些基础但不简单的股票数据
- 为什么会存在1px问题?怎么解决?
- sql 使用过的查询语句
猜你喜欢
在MATLAB中快速画圆(给出圆心坐标和半径就能直接画的那种)
Rearranging log files for leetcode simple question
监控智能回放是什么,如何使用智能回放查询录像
Positioning of high precision welding manipulator
Qt编译QtXlsx库
Smart business card applet business card details page function implementation key code
搜一下导航完整程序源码
[learning] audio and video development from scratch (9) -- nuplayer
ansible自動化運維詳解(一)ansible的安裝部署、參數使用、清單管理、配置文件參數及用戶級ansible操作環境構建
freertos学习02-队列 stream buffer message buffer
随机推荐
利用Js实现一个千分位
2022.4.11-4.17 AI industry weekly (issue 93): the dilemma of AI industry
刨析——浏览器如何工作
The whole house intelligence bet by the giant is driving the "self revolution" of Hisense, Huawei and Xiaomi
每周leetcode - 06 数组专题 7~739~50~offer 62~26~189~9
js常用数组方法
thinkphp6+jwt 实现登录验证
PHP generates short links: convert numbers to letters and letters to numbers
Qt编译QtXlsx库
Rearranging log files for leetcode simple question
一款拥有漂亮外表的Typecho简洁主题_Scarfskin 源码下载
一个没啥L用,但可以装X的IDEA插件
Ansible Automation Operation and Maintenance details (ⅰ) Installation and Deployment, Parameter use, list Management, Profile Parameters and user level ansible operating environment Construction
JS converts tree structure data into one-dimensional array data
Data security has become a hidden danger. Let's see how vivo can make "user data" armor again
AQS & ReentrantLock 实现原理
一篇文章看懂变量提升(hoisting)
C outputs a two-dimensional array with the following characteristics.
[appium] encountered the problem of switching the H5 page embedded in the mobile phone during the test
Data deletion and modification (MySQL)