|
本帖最后由 zopey 于 2017-9-15 16:01 编辑
'*********************************************************
'** 文件时间修改工具 V1.0 ***
'** taller@excelhome.net ***
'** 2007.2.14 ***
'*********************************************************
Option Explicit
Public Const OFS_MAXPATHNAME = 260
Public Const OF_READWRITE = &H2
Public Type OFSTRUCT
cBytes As Byte
fFixedDisk As Byte
nErrCode As Integer
Reserved1 As Integer
Reserved2 As Integer
szPathName(OFS_MAXPATHNAME) As Byte
End Type
Public Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Public Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Declare Function GetFileTime Lib "kernel32" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
Private Declare Function SetFileTime Lib "kernel32" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
Private Declare Function SystemTimeToFileTime Lib "kernel32" (lpSystemTime As SYSTEMTIME, lpFileTime As FILETIME) As Long
Private Declare Function LocalFileTimeToFileTime Lib "kernel32" (lpLocalFileTime As FILETIME, lpFileTime As FILETIME) As Long
Private Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As Long
Private Declare Function FileTimeToLocalFileTime Lib "kernel32" (lpFileTime As FILETIME, lpLocalFileTime As FILETIME) As Long
Private Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hFile As Long) As Long
Sub ModifyFileTime(iTime As Date, iFile As String, Optional mSec As String = 0)
Dim hFile As Long
Dim OFS As OFSTRUCT
Dim NEW_TIME As FILETIME, LOC_TIME As FILETIME
Dim SYS_TIME As SYSTEMTIME
With SYS_TIME
.wYear = VBA.Year(iTime)
.wMonth = VBA.Month(iTime)
.wDay = VBA.Day(iTime)
.wDayOfWeek = VBA.Weekday(iTime) - 1
.wHour = VBA.Hour(iTime)
.wMilliseconds = CInt(mSec)
.wMinute = VBA.Minute(iTime)
.wSecond = VBA.Second(iTime)
End With
Call SystemTimeToFileTime(SYS_TIME, LOC_TIME)
Call LocalFileTimeToFileTime(LOC_TIME, NEW_TIME)
hFile = OpenFile(iFile, OFS, OF_READWRITE)
Call SetFileTime(hFile, NEW_TIME, NEW_TIME, NEW_TIME)
CloseHandle hFile
End Sub
Function ReadFileTime(iFile As String) As String
Dim Ft1 As FILETIME, Ft2 As FILETIME, SysTime As SYSTEMTIME
Dim hFile As Long
Dim OFS As OFSTRUCT
hFile = OpenFile(iFile, OFS, OF_READWRITE)
GetFileTime hFile, Ft1, Ft1, Ft2
FileTimeToLocalFileTime Ft2, Ft1
FileTimeToSystemTime Ft1, SysTime
ReadFileTime = CDate(VBA.DateSerial(SysTime.wYear, SysTime.wMonth, SysTime.wDay) & " " & _
VBA.TimeSerial(SysTime.wHour, SysTime.wMinute, SysTime.wSecond)) & "." & SysTime.wMilliseconds
CloseHandle hFile
End Function
Function ListAllFile(iPath As String, srcSubFolder As Boolean)
Dim FileName(), i As Integer
With Application.FileSearch
.NewSearch
.LookIn = iPath
.SearchSubFolders = srcSubFolder
.FileName = "*.*"
.MatchTextExactly = True
.FileType = msoFileTypeAllFiles
If .Execute() > 0 Then
ReDim FileName(1 To .FoundFiles.Count)
For i = 1 To .FoundFiles.Count
FileName(i) = .FoundFiles(i)
Next i
ListAllFile = FileName()
Else
ListAllFile = ""
End If
End With
End Function
|
评分
-
1
查看全部评分
-
|