#include "mbfileutil.h" #include #include #include CMBFileUtil::CMBFileUtil() { } CMBFileUtil::~CMBFileUtil() { } QString CMBFileUtil::lastModifiedTime(QString fileName) { QFileInfo fileInfo(fileName); QDateTime lastModifiedTime; lastModifiedTime = fileInfo.lastModified(); QString strLastTime = lastModifiedTime.toString("yyyy.MM.dd hh:mm:ss"); return strLastTime; } QString CMBFileUtil::getPath(QString fileName) { int nPos = fileName.lastIndexOf("/"); return fileName.mid(0,nPos); } bool CMBFileUtil::createLevelDir(QString path) { QDir folder; return folder.mkpath(path); } QString CMBFileUtil::genSvrPath(QString rootPath, QString fileName, QString svrPath) { QString tmpSvrPath,retSvrPath; retSvrPath = svrPath; tmpSvrPath = getPath(fileName); tmpSvrPath = tmpSvrPath.replace(rootPath, ""); tmpSvrPath += "/"; // 去除前后斜杠 tmpSvrPath = trimedSlash(tmpSvrPath); svrPath = trimedSlash(svrPath); if( !tmpSvrPath.isEmpty() ){ retSvrPath = svrPath + "/" + tmpSvrPath; } retSvrPath = trimedSlash(retSvrPath); return retSvrPath; } QString CMBFileUtil::trimedSlash(QString str) { int nStartPos = str.indexOf("/"); int nPos = str.lastIndexOf("/"); if( nPos == str.length() -1 ){ str = str.left(nPos); } if( nStartPos == 0 ){ str = str.right(str.length()-1); } return str; }