ID: 336
Viewed: 3628
Added: Aug 19, 2002
Version:
Snippet uploaded by: snippet
Written By: Unknown
Demo: Sorry, no demo
Thank you for your vote. Please wait...
It appears you already voted for this snippet
It appears your vote value was empty
The Win32 API includes native functions that
allow you To change a file's properties, such as time and date, without a
third-party DLL.
allow you To change a file's properties, such as time and date, without a
third-party DLL.
Highlight all by clicking in box
<!---Declaration--->
Option Explicit
'
Private Type FILETIME
dwLowDate As Long
dwHighDate As Long
End Type
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMillisecs As Integer
End Type
Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2
Private Const GENERIC_WRITE = &H40000000
Private Const OPEN_EXISTING = 3
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
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 LocalFileTimeToFileTime Lib _
"kernel32" (lpLocalFileTime As FILETIME, lpFileTime _
As FILETIME) As Long
Private Declare Function SetFileTime Lib "kernel32" _
(ByVal hFile As Long, ByVal MullP As Long, ByVal _
NullP2 As Long, lpLastWriteTime As FILETIME) As Long
Private Declare Function SystemTimeToFileTime Lib _
"kernel32" (lpSystemTime As SYSTEMTIME, lpFileTime _
As FILETIME) As Long
Highlight All
<!---Code--->
Sub Main()
Call SetFileDate("c:autoexec.bat", "10/16/96 12:30 pm")
End Sub
Sub SetFileDate(sFileName As String, sDate As String)
Dim hFile As Long
Dim lResult As Long
Dim udtSysTime As SYSTEMTIME
Dim udtFileTime As FILETIME
Dim udtLocalTime As FILETIME
With udtSysTime
.wYear = Year(sDate)
.wMonth = Month(sDate)
.wDay = Day(sDate)
.wDayOfWeek = WeekDay(sDate) - 1
.wHour = Hour(sDate)
.wMinute = Minute(sDate)
.wSecond = Second(sDate)
End With
lResult = SystemTimeToFileTime(udtSysTime, _
udtLocalTime)
lResult = LocalFileTimeToFileTime(udtLocalTime, _
udtFileTime)
hFile = CreateFile(sFileName, GENERIC_WRITE, _
FILE_SHARE_READ _
Or FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, _
0, 0)
lResult = SetFileTime(hFile, ByVal 0&, ByVal 0&, _
udtFileTime)
Call CloseHandle(hFile)
End Sub;
No Comments to show
Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.
Adding your comment. Please wait...
Thanks for adding your comment!. After further review it will be added.
There was a problem adding your comment. Please try again.
Please complete all the fields in the form before sending.