Skip to content

Commit

Permalink
Edited for less complicated recursive file manager deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
erinharrington-12 committed Dec 17, 2024
1 parent a9cb622 commit 5cc4cc2
Showing 1 changed file with 27 additions and 28 deletions.
55 changes: 27 additions & 28 deletions src/FileUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
else
{
qDebug() << "Failed to remove directory.";
}
}

0 comments on commit 5cc4cc2

Please sign in to comment.