Qt 获取文件夹中的文件夹名字

环境

VS2015 qt5.9.7 64位

包含的头文件

1 #include <QDir>
2 #include <QDebug>
3 #include <QMessageBox>

代码

 1 //--1 判断文件夹是否存在
 2 QString folderPath = "H:\Pro";
 3 QDir dir(folderPath);
 4 if(!dir.exists())
 5 {
 6     QMessageBox::critical(this,tr("错误"),tr("文件夹找不到"));
 7     return;
 8 }
 9 
10 //--2 获取当前路径下所有的文件夹名字
11 QStringList names = dir.entryList(QDir::Dirs);
12 
13 //--3 删除当前文件夹和上级文件夹(温馨提示:隐藏的文件夹获取不了)
14 names.removeOne(".");
15 names.removeOne("..");
16 
17 //--4 打印出获取的文件名
18 qDebug() << "names: " << names;
原文地址:https://www.cnblogs.com/ybqjymy/p/13632898.html