OMG_Soruce
OMG_Soruce

Reputation: 106

Removing Directory in Qt

I want to remove folder:

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

Failed, because there is a subfolder:

TEST
  └A
   └B

Also tried another way:

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

This time it fails with:

rm: Inappropriate options -- 'L'

How can I delete the directory with sub-directories?

Upvotes: 1

Views: 1845

Answers (1)

Alexander V
Alexander V

Reputation: 8698

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

Upvotes: 3

Related Questions