当前位置:网站首页>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
边栏推荐
- 关于ORB——SLAM运行中关键帧位置越来越近的异常说明
- JS common array methods
- Ubuntu安装Mysql并查询平均成绩
- Qt读写XML文件
- 跨域配置报错: When allowCredentials is true, allowedOrigins cannot contain the special value “*“
- 多目视觉SLAM
- Data security has become a hidden danger. Let's see how vivo can make "user data" armor again
- mysql查询字符串类型的字段使用数字类型查询时问题
- 分组背包呀
- 输入/输出系统
猜你喜欢
There are some problems when using numeric type to query string type fields in MySQL
Draw a circle quickly in MATLAB (the one that can be drawn directly given the coordinates and radius of the center of the circle)
PyQt5开发之QTableWidget表头自定义与美化(附源代码下载)
总线结构概述
Qt读写XML文件
2022.4.11-4.17 AI行业周刊(第93期):AI行业的困局
[learning] audio and video development from scratch (9) -- nuplayer
Thinkphp6 + JWT realizes login verification
【Appium】测试时遇到手机内嵌H5页面的切换问题
WordPress love navigation theme 1.1.3 simple atmosphere website navigation source code website navigation source code
随机推荐
Rearranging log files for leetcode simple question
Talk about the basic but not simple stock data
关于ORB——SLAM运行中关键帧位置越来越近的异常说明
华硕笔记本电脑重装系统后不能读取usb,不能上网
[untitled]
Ubuntu安装Mysql并查询平均成绩
Usage of databinding
欧圣电气深交所上市:市值52亿 陆为东父女为美国籍
岛屿的个数
LeetCode15. Sum of three
[effective go Chinese translation] function
One click cleanup of pycharm and jupyter cache files under the project
Compiler des questions de principe - avec des réponses
User manual of Chinese version of solidity ide Remix
AQS & ReentrantLock 实现原理
Qt读写XML文件
Distributed service governance Nacos
Install MySQL for Ubuntu and query the average score
Find the largest of 3 strings (no more than 20 characters per string).
C outputs a two-dimensional array with the following characteristics.