#include <QDir>
#include <QFileInfoList>
#include <QApplication>
bool removeDirectory(const QString& path)
{
if (path.isEmpty())
return false;
QDir dir(path);
if(!dir.exists())
return true;
dir.setFilter(QDir::AllEntries | QDir::NoDotAndDotDot);
QFileInfoList fileList = dir.entryInfoList();
foreach (QFileInfo fi, fileList) {
if (fi.isFile())
fi.dir().remove(fi.fileName());
else
removeDirectory(fi.absoluteFilePath());
}
return dir.rmpath(dir.absolutePath());
}
bool copyDirectory(const QString srcPath, const QString dstPath)
{
QDir dir(srcPath);
if (! dir.exists())
return false;
foreach (QString path, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {
QString dstPathNew = dstPath + path + QDir::separator();
if (!dir.mkpath(dstPathNew))
return false;
QApplication::processEvents();
if (!copyDirectory(srcPath + path + QDir::separator(), dstPathNew))
return false;
}
foreach (QString file, dir.entryList(QDir::Files)) {
if (QFileInfo::exists(dstPath + QDir::separator() + file))
dir.remove(dstPath + file);
if (!QFile::copy(srcPath + file, dstPath + file))
return false;
QApplication::processEvents();
}
return true;
}