2016-01-07 106 views
0

我想删除文件夹:删除目录中的Qt

QDir dir1; 
dir.remove("TEST"); 

失败,因为有一个子文件夹:

TEST 
    └A 
    └B 

也试过另一种方式:

QProcess pProcess = new QProcess; 
QString total; 
total="TEST"; 
list1<<"-r"+total; 
pProcess->execute("rm",list1); 

这一次失败:

rm: Inappropriate options -- 'L' 

如何删除具有子目录的目录?

+3

[Qt中删除非空文件夹(http://stackoverflow.com/questions/11050977/removing-a-non-empty-folder-in-qt) – demonplus

+0

@demonplus感谢的可能的复制,但删除不是。我的Qt版本4.8 –

+1

也许你应该试试list1 <<“-r”<< total; – Evgeny

回答

2
bool removeDirRecursively(const QString& dirPath) 
{ 
    QDir dir(dirPath); 
    bool r = dir.removeRecursively(); 
    qDebug() << "The directory remove operation " << 
     (r ? "finished successfully" : "failed"); 
}