puzhibing
2024-02-05 640ff18d2d7f4be02ddb7f8f75e899f05545eb98
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
72
73
74
75
76
77
78
79
80
81
<%
 
Class PathFormatter
    Public Function Format( ByVal pathFormat, ByVal filename )
        Dim ext, name
        If IsEmpty( format ) Then
            format = "{yyyy}{mm}{dd}{hh}{ii}{ss}{rand:6}"
        End If
 
        Set invalidPattern = new RegExp
        invalidPattern.Pattern = "[\\\/\:\*\?\<\>\|""]"
        invalidPattern.Global = true
        filename = invalidPattern.Replace( filename, "" )
 
        ext = GetExt( filename )
        name = GetNameWithoutExt( filename )
 
        pathFormat = Replace( pathFormat, "{filename}", name )
        pathFormat = Replace( pathFormat, "{time}", TimeStamp() )
        pathFormat = Replace( pathFormat, "{yyyy}", Year(Now) )
        pathFormat = Replace( pathFormat, "{yy}", Year(Now) Mod 100 )
        pathFormat = Replace( pathFormat, "{mm}", LeadZero( Month(Now) ) )
        pathFormat = Replace( pathFormat, "{dd}", LeadZero( Day(Now) ) )
        pathFormat = Replace( pathFormat, "{hh}", LeadZero( Hour(Now) ) )
        pathFormat = Replace( pathFormat, "{ii}", LeadZero( Minute(Now) ) )
        pathFormat = Replace( pathFormat, "{ss}", LeadZero( Second(Now) ) )
 
        Set randPattern = new RegExp
        randPattern.Pattern = "{rand(\:?)(\d+)}"
        Set matches = randPattern.Execute(pathFormat)
        If matches.Count Then
            Set match = matches(0)
            digit = 6
            If match.SubMatches.Count > 1 Then
                digit = 0 + match.SubMatches(1)
            End If
            min = 1
            Do While digit > 0
                min = min * 10
                digit = digit - 1
            Loop
            max = min * 10
            pathFormat = randPattern.Replace( pathFormat, Rand( min, max ) )
        End If
        Format = pathFormat + ext
    End Function
    
    Private Function GetExt( file )
        GetExt = Right( file, Len(file) - InStrRev(file, ".") + 1 )
    End Function
 
    Private Function GetNameWithoutExt( file )
        GetNameWithoutExt = Left( file, InStrRev(file, ".") - 1 )
    End Function
 
    Private Function TimeStamp()
        TimeStamp = DateDiff("s", "1970-1-1 8:00:00", Now())
    End Function
 
    Private Function Rand( min, max )
        Randomize 
        Rand = Int( (max - min + 1) * Rnd + min )
    End Function
 
    Private Function GetFormatedDate()
        Dim yyyy, mm, dd
        yyyy = Year(Date)
        mm = LeadZero(Month(Date))
        dd = LeadZero(Day(Date))
        GetFormatedDate = yyyy & mm & dd
    End Function
 
    Private Function LeadZero( number )
        If number < 10 Then
            LeadZero = "0" & number
        Else
            LeadZero = number
        End If
    End Function
End Class
%>