Golom, when I tried it last year I received a run-time error. I'll try it again to find out what the error was. My application was developed on XP and installed as a runtime (with the appropriate dlls) on the Win98 PC.
Nevertheless, you can use GetFileTime API function to retrieve this information. This function retrieves creation date, last modification date and last access date for the given file handle.
The date information returned by this function is a Win32 FILETIME structure. You need to do some conversion to make it a VB Date data type for further use in VB code.
___
[tt]
Option Explicit
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function GetFileTime Lib "kernel32" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function FileTimeToLocalFileTime Lib "kernel32" (lpFileTime As FILETIME, lpLocalFileTime As FILETIME) As Long
Private Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As Long
Private Const GENERIC_READ = &H80000000
Private Const OPEN_EXISTING = 3
Private 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 Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Sub Form_Load()
Dim dtCreated As Date, dtModified As Date, dtAccessed As Date
VBGetFileTimes "C:\AUTOEXEC.BAT", dtCreated, dtModified, dtAccessed
Debug.Print "Created:", dtCreated
Debug.Print "Modified:", dtModified
Debug.Print "Accessed:", dtAccessed
End Sub
Function VBGetFileTimes(FileName As String, Optional Created As Date, Optional Modified As Date, Optional Accessed As Date) As Boolean
Dim hFile As Long, ft1 As FILETIME, ft2 As FILETIME, ft3 As FILETIME
hFile = CreateFile(FileName, GENERIC_READ, 0, ByVal 0&, OPEN_EXISTING, 0, 0)
If hFile Then
GetFileTime hFile, ft1, ft2, ft3
CloseHandle hFile
Created = FileTimeToVBTime(ft1)
Accessed = FileTimeToVBTime(ft2)
Modified = FileTimeToVBTime(ft3)
VBGetFileTimes = True
End If
End Function
Private Function FileTimeToVBTime(ft As FILETIME) As Date
Dim lft As FILETIME, st As SYSTEMTIME
FileTimeToLocalFileTime ft, lft
FileTimeToSystemTime lft, st
FileTimeToVBTime = DateSerial(st.wYear, st.wMonth, st.wDay) + TimeSerial(st.wHour, st.wMinute, st.wSecond)
End Function[/tt]
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.