#include
#include
#include
#include
#include
#include
#include
#include
#include
static QJsonArray fList;
static int extraSize = 0;
using namespace std;
void folderHandler(QString folderPath) {
for (QFileInfo f : QDir(folderPath).entryInfoList()) {
if (!f.isDir()) {
QJsonObject fileInfo {
{"fileName", f.fileName()},
{"size", f.size()},
{"path", f.filePath()}
};
fList.push_back(fileInfo);
} else if (f.fileName() != "." && f.fileName() != "..") {
folderHandler(f.absoluteFilePath());
}
}
}
void fileHandler() {
QJsonArray copyFileList = fList;
for (int i = 0; i < fList.size(); i++) {
QJsonArray duplicateList;
QJsonObject buf = fList[i].toObject();
for (int k = 0; k < copyFileList.size(); k++) {
if (copyFileList[k].toObject().value("fileName") == buf.value("fileName") &&
copyFileList[k].toObject().value("size") == buf.value("size")) {
duplicateList.push_back(copyFileList[k].toObject());
copyFileList.removeAt(k);
k--;
}
}
if (duplicateList.size() > 1) {
extraSize += duplicateList[0].toObject().value("size").toInt() * (duplicateList.size()-1);
for (QJsonValueRef d : duplicateList) {
qDebug() << d.toObject().value("path").toString();
}
}
}
}
int main()
{
QString path = "C:\\Text";
qDebug() << "root dir" << QDir(path).absolutePath();
//folderHandler(path);
fileHandler();
qDebug() << "extra size" << extraSize << "b";
}