在 Qt 中删除目录

Removing Directory in 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'

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

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