本帖最后由 czjt1234 于 2023-4-5 19:00 编辑
vbs- s = "D:\aaa" '指定一个文件夹
-
- Set oWshShell = CreateObject("WScript.Shell")
- oWshShell.CurrentDirectory = s
- Set oFSO = CreateObject("Scripting.FileSystemObject")
- Set oShell = CreateObject("Shell.Application")
- Set oFolder = oShell.NameSpace(s)
- Set oFolderItems = oFolder.Items()
- oFolderItems.Filter &H40 + &H80 + &H10000, "*.*"
- For i = 0 To 500
- If oFolder.GetDetailsOf(Null, i) = "创建媒体日期" Then n = i
- Next
- For Each i In oFolderItems
- s = oFolder.GetDetailsOf(i, n)
- If s <> "" Then
- s = RePlace(s, ChrW(8206), "")
- s = RePlace(s, ChrW(8207), "")
- s = "-" & F_D_T(s, "yyyymmdd") & "."
- i.Name = oFSO.GetBaseName(i.Name) & s & oFSO.GetExtensionName(i.Name)
- End If
- Next
- MsgBox "ok"
-
- Function F_D_T(ByVal d, ByVal s)
- Dim oSWbemDateTime, oWMI, i, TimeZone
- Select Case UCase(s)
- Case "CIM_DATETIME"
- Set oSWbemDateTime = CreateObject("WbemScripting.SWbemDateTime")
- oSWbemDateTime.SetVarDate d
- F_D_T = oSWbemDateTime.Value
- Case "INTERVAL FORMAT"
- Set oSWbemDateTime = CreateObject("WbemScripting.SWbemDateTime")
- oSWbemDateTime.SetVarDate d
- oSWbemDateTime.IsInterval = True
- F_D_T = oSWbemDateTime.Value
- Case "FILENAME" 'UTC时间
- Set oSWbemDateTime = CreateObject("WbemScripting.SWbemDateTime")
- oSWbemDateTime.SetVarDate d
- F_D_T = oSWbemDateTime.GetFileTime(False)
- Case "UNIX" '10位Unix时间戳,UTC时间
- Set oWMI = GetObject("Winmgmts:\\.\Root\Cimv2")
- For Each i In oWMI.ExecQuery("SELECT * FROM Win32_OperatingSystem")
- TimeZone = i.CurrentTimeZone
- Next
- i = DateDiff("s", #1970-01-01 00:00:00#, d)
- F_D_T = i - TimeZone * 60
- Case Else
- s = Replace(s, "yyyy", Year(d), 1, -1, vbTextCompare)
- s = Replace(s, "yy", Right(Year(d), 2), 1, -1, vbTextCompare)
- s = Replace(s, "mm", Right("0" & Month(d), 2), 1, -1, vbBinaryCompare)
- s = Replace(s, "m", Month(d), 1, -1, vbBinaryCompare)
- s = Replace(s, "dd", Right("0" & Day(d), 2), 1, -1, vbTextCompare)
- s = Replace(s, "d", Day(d), 1, -1, vbTextCompare)
- s = Replace(s, "HH", Right("0" & Hour(d), 2), 1, -1, vbTextCompare)
- s = Replace(s, "H", Hour(d), 1, -1, vbTextCompare)
- s = Replace(s, "MM", Right("0" & Minute(d), 2), 1, -1, vbBinaryCompare)
- s = Replace(s, "M", Minute(d), 1, -1, vbBinaryCompare)
- s = Replace(s, "SS", Right("0" & Second(d), 2), 1, -1, vbTextCompare)
- s = Replace(s, "S", Second(d), 1, -1, vbTextCompare)
- F_D_T = s
- End Select
- End Function
复制代码
|