VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



'Get filetime using GetFileTime API

by Karthikeyan (187 Submissions)
Category: Windows API Call/Explanation
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Tue 23rd January 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

'Get filetime using GetFileTime API

API Declarations


Private Const OF_READWRITE = &H2
Private Const OF_REOPEN = &H8000
Private Const OF_SHARE_COMPAT = &H0
Private Const OF_SHARE_DENY_NONE = &H40
Private Const OF_SHARE_DENY_READ = &H30
Private Const OF_SHARE_DENY_WRITE = &H20
Private Const OF_SHARE_EXCLUSIVE = &H10
Private Const OF_VERIFY = &H400
Private Const OF_WRITE = &H1
Private Const OFS_MAXPATHNAME = 128
Private Type OFSTRUCT
cBytes As Byte
fFixedDisk As Byte
nErrCode As Integer
Reserved1 As Integer
Reserved2 As Integer
szPathName(OFS_MAXPATHNAME) As Byte
End Type
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime 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
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 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 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 hObject As Long) As Long

Rate 'Get filetime using GetFileTime API



'http://www.geocities.com/marskarthik
'http://marskarthik.virtualave.net
'Email: [email protected]
Private Sub Form_Load()
Dim hFile As Long, rval As Long
Dim buff As OFSTRUCT
Dim ctime As FILETIME, atime As FILETIME, wtime As FILETIME
Dim ftime As SYSTEMTIME
'Open the File for Reading
hFile = OpenFile("c:\waste.txt", buff, OF_READ)
If hFile Then
'Get File time
rval = GetFileTime(hFile, ctime, atime, wtime)
'Convert File Time Zone to Local
rval = FileTimeToLocalFileTime(ctime, ctime)
'Convert File Time Format to System Time Format
rval = FileTimeToSystemTime(ctime, ftime)
MsgBox "File is created on " & ftime.wDay & "-" & ftime.wMonth & "-" & ftime.wYear & _
Chr(13) & "File is created at " & ftime.wHour & ":" & ftime.wMinute & ":" & ftime.wSecond
'Convert File Time Zone to Local
rval = FileTimeToLocalFileTime(wtime, wtime)
'Convert File Time Format to System Time Format
rval = FileTimeToSystemTime(wtime, ftime)
MsgBox "File is modified on " & ftime.wDay & "-" & ftime.wMonth & "-" & ftime.wYear & _
Chr(13) & "File is modified at " & ftime.wHour & ":" & ftime.wMinute & ":" & ftime.wSecond
'Convert File Time Zone to Local
rval = FileTimeToLocalFileTime(atime, atime)
'Convert File Time Format to System Time Format
rval = FileTimeToSystemTime(atime, ftime)
MsgBox "File is Lastly Accessed on " & ftime.wDay & "-" & ftime.wMonth & "-" & ftime.wYear & _
Chr(13) & "File is Lastly Accessed at " & ftime.wHour & ":" & ftime.wMinute & ":" & ftime.wSecond
End If
'Close the File Handle
rval = CloseHandle(hFile)
End
End Sub

Download this snippet    Add to My Saved Code

'Get filetime using GetFileTime API Comments

No comments have been posted about 'Get filetime using GetFileTime API. Why not be the first to post a comment about 'Get filetime using GetFileTime API.

Post your comment

Subject:
Message:
0/1000 characters