| Private Const GENERIC_WRITE = &H40000000
Private Const OPEN_EXISTING = 3
Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) 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 CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function LocalFileTimeToFileTime Lib "kernel32" (lpLocalFileTime As FILETIME, lpFileTime As FILETIME) As Long
Public Sub SetFileDateTime(ByRef vsFile As String, ByVal vdIn As Date)
Dim tFileTime As FILETIME
Dim tLocalTime As FILETIME
Dim tSystemTime As SYSTEMTIME
Dim hFile As Long
hFile = CreateFile(vsFile, GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0, 0)
If hFile <> -1 Then
With tSystemTime
.wYear = Year(vdIn)
.wMonth = Month(vdIn)
.wDay = Day(vdIn)
.wDayOfWeek = Weekday(vdIn) - 1
.wHour = Hour(vdIn)
.wMinute = Minute(vdIn)
.wSecond = Second(vdIn)
.wMilliseconds = 0
End With
SystemTimeToFileTime tSystemTime, tLocalTime
LocalFileTimeToFileTime tLocalTime, tFileTime
SetFileTime hFile, tFileTime, tFileTime, tFileTime
CloseHandle hFile
End If
End Sub |
| By Renfield |