-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
37 lines (34 loc) · 1.17 KB
/
Copy pathmain.cpp
File metadata and controls
37 lines (34 loc) · 1.17 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
#include <QCoreApplication>
#include <QCryptographicHash>
#include <QDirIterator>
#include <QTextStream>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QTextStream qout(stdout);
QDirIterator *it = new QDirIterator(QCoreApplication::arguments().at(1), QDir::Files | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
QFile *file = nullptr;
QSet<QByteArray> set;
while (it->hasNext()) {
file = new QFile(it->next());
file->open(QIODevice::ReadOnly);
set.insert(QCryptographicHash::hash(file->readAll(), QCryptographicHash::Md5));
file->close();
delete file;
}
delete it;
it = new QDirIterator(QCoreApplication::arguments().at(2), QDir::Files | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
while (it->hasNext()) {
file = new QFile(it->next());
file->open(QIODevice::ReadOnly);
if (set.contains(QCryptographicHash::hash(file->readAll(), QCryptographicHash::Md5))) {
qout << "Deleting " << it->filePath() << Qt::endl;
file->remove();
} else {
file->close();
}
delete file;
}
delete it;
return 0;
}