QT刪除非空文件夾


 1     int choose;
 2     choose = QMessageBox::warning(NULL,"warning","確定刪除該文件?",QMessageBox::Yes | QMessageBox::No,QMessageBox::Yes);
 3     if(choose == QMessageBox::No)   //做一個判斷,如果選擇”NO“,則返回
 4     {
 5         return;
 6     }
 7     else if(choose == QMessageBox::Yes)  //如果選擇”YES“,執行下面代碼
 8     {
 9         QString path = dirpath;//指定路徑文件
10         QDir dir(path);
11 
12         dir.setFilter(QDir::AllEntries | QDir::NoDotAndDotDot);
13         QFileInfoList fileList = dir.entryInfoList();
14         foreach (QFileInfo fi,  fileList)
15         {
16             if(fi.isFile())  //是文件,刪除
17             {
18                 fi.dir().remove(fi.fileName());
19             }
20             else
21             {
22                 return;
23             }
24         }
25         if(dir.exists() == true)
26         {
27         dir.rmpath(dir.absolutePath()); //刪除文件夾
28         QMessageBox::information(NULL, tr(""),tr("已刪除!!!"),QMessageBox::Yes);
29         }
30         else
31         {
32             QMessageBox::warning(NULL, tr(""),tr("無文件!!!"),QMessageBox::Yes);
33         }
34     }

 


免責聲明!

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



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