这是一个用来监控本地文件夹变化的服务
w1146869587
2021-11-09 f5e3a3a6785cd9305c476eadf329c8ae00161add
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "mbfileutil.h"
#include <QFileInfo>
#include <QDateTime>
#include <QDir>
 
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;
}