qt 移动文件夹到另一目录下
#include <QDir>
bool delDir(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 file, fileList){
if (file.isFile()){
file.dir().remove(file.fileName());
}else{
DelDir(file.absoluteFilePath());
}
}
return dir.rmdir(dir.absolutePath());
}
bool toMove(const QString& srcPath, const QString & desPath){
QStringList fileNames = getFiles(srcPath);
foreach (const QString& filename, fileNames) {
QString temp = filename;
QString suffix = temp.remove(0,srcPath.length());
QString desFileName = desPath + suffix;
QFileInfo fileInfo(desFileName);
if(fileInfo.exists())
{
QFile::remove(desFileName);
}
else
{
if(!fileInfo.dir().exists())
{
fileInfo.dir().mkpath(fileInfo.absolutePath());
}
}
qDebug()<<QFile::rename(filename, desFileName);
}
return delDir(srcPath);
}