diff --git a/src/FileUtils.cpp b/src/FileUtils.cpp index 8db98040..0f423d68 100644 --- a/src/FileUtils.cpp +++ b/src/FileUtils.cpp @@ -8,48 +8,47 @@ bool FileUtils::copy(const QString &path, const QString &newPath) { QFileInfo input(path); - if(!input.exists()) return false; - - if(input.isDir()) { - if(!QDir(newPath).mkpath(input.fileName())) { + if (!input.exists()) + return false; + + if (input.isDir()) + { + if (!QDir(newPath).mkpath(input.fileName())) + { qWarning() << "QDir(newPath).mkpath(input.fileName())" - << "failed. (newPath =" << newPath << ")"; + << "failed. (newPath =" << newPath << ")"; return false; } QFileInfoList entries = QDir(input.absoluteFilePath()).entryInfoList(QDir::NoDotAndDotDot | QDir::Files | QDir::Dirs); qDebug() << QDir(input.absoluteFilePath()).entryList(QDir::NoDot | QDir::NoDotDot); - foreach(const QFileInfo &entry, entries) { - if(!copy(entry.absoluteFilePath(), newPath + "/" + input.fileName())) { + foreach (const QFileInfo &entry, entries) + { + if (!copy(entry.absoluteFilePath(), newPath + "/" + input.fileName())) + { return false; } } return true; - } else if(input.isFile()) { + } + else if (input.isFile()) + { return QFile::copy(path, newPath + "/" + input.fileName()); } - + return false; } + bool FileUtils::rm(const QString &path) { - QFileInfo input(path); - if(input.isDir()) { - qDebug() << "In directory" << input.absoluteFilePath(); - QFileInfoList entries = QDir(input.absoluteFilePath()).entryInfoList(QDir::NoDotAndDotDot | QDir::Files | QDir::Dirs); - qDebug() << QDir(input.absoluteFilePath()).entryList(QDir::NoDotAndDotDot | QDir::Files | QDir::Dirs); - foreach(const QFileInfo &entry, entries) { - qDebug() << "Recursively removing" << entry.absoluteFilePath(); - if(!rm(entry.absoluteFilePath())) { - return false; - } - } - qDebug() << "Removing" << path; - return QDir().rmdir(input.absoluteFilePath()); - } else if(input.isFile()) { - qDebug() << "Removing" << path; - return QFile::remove(path); + QDir dir(path); + + if (dir.removeRecursively()) + { + qDebug() << "Directory removed successfully."; } - - return false; -} \ No newline at end of file + else + { + qDebug() << "Failed to remove directory."; + } +}