|
|
|
|
|
#include "HubBase.h"
|
|
|
|
|
|
#include "qfile.h"
|
|
|
|
|
|
#include "qdir.h"
|
|
|
|
|
|
#include "qdatetime.h"
|
|
|
|
|
|
|
|
|
|
|
|
bool hubBase::copyPath2Path(QString sourcePath, QString dstPath, bool coverFileIfExist)
|
|
|
|
|
|
{
|
|
|
|
|
|
dstPath.replace("\\", "/");
|
|
|
|
|
|
if (sourcePath == dstPath) {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!QFile::exists(sourcePath)){
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
QDir *createfile = new QDir;
|
|
|
|
|
|
bool exist = createfile->exists(dstPath);
|
|
|
|
|
|
if (exist){
|
|
|
|
|
|
if (coverFileIfExist){
|
|
|
|
|
|
createfile->remove(dstPath);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
delete createfile;
|
|
|
|
|
|
if (!QFile::copy(sourcePath, dstPath)) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool hubBase::deleteDirectory(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
|
|
|
|
|
|
deleteDirectory(fi.absoluteFilePath());
|
|
|
|
|
|
}
|
|
|
|
|
|
return dir.rmpath(dir.absolutePath());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool hubBase::mkdir(QString path)
|
|
|
|
|
|
{
|
|
|
|
|
|
QDir dir;
|
|
|
|
|
|
return dir.mkdir(path);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString hubBase::baseNameofPath(const QString& str)
|
|
|
|
|
|
{
|
|
|
|
|
|
QFileInfo fi(str);
|
|
|
|
|
|
return fi.baseName();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool hubBase::removeFile(QString strFile)
|
|
|
|
|
|
{
|
|
|
|
|
|
QFile file(strFile);
|
|
|
|
|
|
return file.remove();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString hubBase::genDateTime(QString strFormat /*= "yyyy-MM-dd hh:mm:ss"*/)
|
|
|
|
|
|
{
|
|
|
|
|
|
return QDateTime::currentDateTime().toString(strFormat);
|
|
|
|
|
|
}
|
|
|
|
|
|
QString hubBase::genTime(QString strFormat /* = "yyyy-MM-dd hh:mm:ss" */)
|
|
|
|
|
|
{
|
|
|
|
|
|
return QDateTime::currentDateTime().toString(strFormat);
|
|
|
|
|
|
}
|
|
|
|
|
|
QString hubBase::pathSuffix(QString str)
|
|
|
|
|
|
{
|
|
|
|
|
|
QFileInfo fileinfo = QFileInfo(str);
|
|
|
|
|
|
return fileinfo.suffix();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool hubBase::reNameDirectory(const QString &strOld, const QString &strNew)
|
|
|
|
|
|
{
|
|
|
|
|
|
QDir dir;
|
|
|
|
|
|
if(dir.rename(strOld, strNew))
|
|
|
|
|
|
return true;
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
bool hubBase::reNameFile(const QString &strOld, const QString &strNew)
|
|
|
|
|
|
{
|
|
|
|
|
|
QFile file(strOld);
|
|
|
|
|
|
if(file.rename(strNew))
|
|
|
|
|
|
return true;
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|