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;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM