環境
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;
