#include "sfilecopy.h"
SFileCopy::SFileCopy(QObject *parent) :
QObject(parent)
{
m_createfile = new QDir();
}
SFileCopy::~SFileCopy()
{
if (m_createfile)
{
m_createfile = Q_NULLPTR;
delete m_createfile;
}
}
bool SFileCopy::copyFileToPath(QString sourceDir, QString toDir, bool coverFileIfExist)//拷贝文件
{
toDir.replace("\\", "/");
if (sourceDir == toDir)
{
return true;
}
if (!QFile::exists(sourceDir))
{
return false;
}
bool exist = m_createfile->exists(toDir);
if (exist)
{
if (coverFileIfExist)
{
m_createfile->remove(toDir);
}
}
if (!QFile::copy(sourceDir, toDir))
{
return false;
}
return true;
}
//拷贝文件夹
bool SFileCopy::copyDirectoryFiles(const QString &fromDir, const QString &toDir, bool coverFileIdExist)
{
QDir sourceDir(fromDir);
QDir targetDir(toDir);
qDebug() << "copyDirectoryFiles:" <<fromDir << toDir;
if (!targetDir.exists())
if (!targetDir.mkdir(targetDir.absolutePath()))
return false;
QFileInfoList fileInfoList = sourceDir.entryInfoList();
if (m_firstRead)
{
int isfileTMP = 0;
qDebug() << "a copyDirectoryFiles:" << fileInfoList.count();
foreach (QFileInfo fileInfo, fileInfoList)
{
if (fileInfo.isFile())
isfileTMP++;
}
m_total = fileInfoList.count() - 2 - isfileTMP;
m_value = 0;
m_firstRead = false;
qDebug()<< "a copyDirectoryFiles:" << fileInfoList.count() << m_total << isfileTMP;
emit sigCopyDirStation(m_value/m_total);
if (m_value == m_total)
{
m_firstRead = true;
emit sigCopyDirStation(1);
emit sigCopyDirOver();
}
}
else
{
m_value++;
qDebug()<< "a copyDirectoryFiles:" << m_value << m_total;
emit sigCopyDirStation(m_value/m_total);
if ((m_value/m_total == 1)||(m_value > m_total)||(m_value == m_total))
{
m_firstRead = true;
emit sigCopyDirOver();
}
}
foreach (QFileInfo fileInfo, fileInfoList)
{
if (fileInfo.fileName() == "." || fileInfo.fileName() == "..")
continue;
if (fileInfo.isDir())
if (!copyDirectoryFiles(fileInfo.filePath(), targetDir.filePath(fileInfo.fileName()), coverFileIdExist))
return false;
else
if (coverFileIdExist && targetDir.exists(fileInfo.fileName()))
targetDir.remove(fileInfo.fileName());
if (!QFile::copy(fileInfo.filePath(), targetDir.filePath(fileInfo.fileName())))
return false;
}
return true;
}
Qt文件或文件夹拷贝
2星 需积分: 45 15 浏览量
2019-01-09
15:39:04
上传
评论 1
收藏 5KB ZIP 举报
WANGZHEN`
- 粉丝: 432
- 资源: 44
最新资源
- Screenshot_20240427_031602.jpg
- 网页PDF_2024年04月26日 23-46-14_QQ浏览器网页保存_QQ浏览器转格式(6).docx
- 直接插入排序,冒泡排序,直接选择排序.zip
- 在排序2的基础上,再次对快排进行优化,其次增加快排非递归,归并排序,归并排序非递归版.zip
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
- 课设-内部排序算法比较 包括冒泡排序、直接插入排序、简单选择排序、快速排序、希尔排序、归并排序和堆排序.zip
- Python排序算法.zip
- C语言实现直接插入排序、希尔排序、选择排序、冒泡排序、堆排序、快速排序、归并排序、计数排序,并带图详解.zip
- 常用工具集参考用于图像等数据处理
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈