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     }
原文地址:https://www.cnblogs.com/ruandahua/p/10740780.html