add helper to purge directories recursively
This commit is contained in:
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
|
|
||||||
|
#include <QDir>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
@ -66,6 +67,23 @@ bool has_exe(const QString &exe)
|
|||||||
return false; // Not found!
|
return false; // Not found!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// recursively remove all contents from a directory
|
||||||
|
|
||||||
|
void purge_directory(const QString &dir)
|
||||||
|
{
|
||||||
|
QDir directory(dir);
|
||||||
|
|
||||||
|
directory.setFilter(QDir::AllEntries | QDir::NoDotAndDotDot);
|
||||||
|
const auto &entries = directory.entryList();
|
||||||
|
for (auto &entry : entries) {
|
||||||
|
if (!directory.remove(entry)) {
|
||||||
|
directory.cd(entry);
|
||||||
|
directory.removeRecursively();
|
||||||
|
directory.cdUp();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Local Variables:
|
// Local Variables:
|
||||||
// c-basic-offset: 4
|
// c-basic-offset: 4
|
||||||
// End:
|
// End:
|
||||||
|
|||||||
@ -25,6 +25,9 @@ extern char *mystrdup(const QString &text);
|
|||||||
// find if executable is in path
|
// find if executable is in path
|
||||||
extern bool has_exe(const QString &exe);
|
extern bool has_exe(const QString &exe);
|
||||||
|
|
||||||
|
// recursively purge a directory
|
||||||
|
extern void purge_directory(const QString &dir);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
// Local Variables:
|
// Local Variables:
|
||||||
// c-basic-offset: 4
|
// c-basic-offset: 4
|
||||||
|
|||||||
Reference in New Issue
Block a user