-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeletedialog.cpp
More file actions
63 lines (53 loc) · 1.58 KB
/
deletedialog.cpp
File metadata and controls
63 lines (53 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <QtGui>
#include <QMessageBox>
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <QFileInfoList>
#include <QCoreApplication>
#include "deletedialog.h"
DeleteDialog::DeleteDialog()
{
}
/**
DeleteDialog::deleteDir()
Delete the whole directory tree.
*/
bool DeleteDialog::deleteDir(const QString & dir)
{
QDir srcDir(dir);
if (!srcDir.exists()) {
QFileInfo srcInfo(dir);
if (srcInfo.isFile()) {
return QFile::remove(dir);
} else {
return false;
qDebug() << "not a dir and not a file" << dir;
}
}
QFileInfoList srcList = srcDir.entryInfoList(
QDir::Dirs|QDir::Files|QDir::Readable|QDir::NoDotAndDotDot);
qDebug() << "processing" << srcList.count() << "entries";
QFileInfo di;
foreach (di, srcList) {
qDebug() << "Deleting file" << di.absoluteFilePath();
if (di.isDir()) {
if (deleteDir(di.absoluteFilePath())) {
continue;
} else {
qDebug() << "DeleteDialog::deleteDir() error: " <<
di.absoluteFilePath();
return false;
}
} else if (di.isFile()) {
if (!di.isWritable()) {
//implicit behaviour is to copy everything possible
qDebug() << di.absoluteFilePath() << "not readable!";
continue;
}
qDebug() << "removing" << di.absoluteFilePath();
QFile::remove(di.absoluteFilePath());
} //isFile()
} //foreach
return srcDir.rmdir(".");
}