VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



'Set the File modified time to Current System Time using GetSystemTimeAsFileTime 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)

'Set the File modified time to Current System Time using GetSystemTimeAsFileTime 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 SetFileTime Lib "kernel32" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
Private Declare Sub GetSystemTimeAsFileTime Lib "kernel32.dll" (lpSystemTimeAsFileTime As FILETIME)
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 'Set the File modified time to Current System Time using GetSystemTimeAsFileTime 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
'Open file for Writing
hFile = OpenFile("c:\waste.txt", buff, OF_WRITE)
If hFile Then
'Get the current System Time as File Time Format
GetSystemTimeAsFileTime wtime
'Set Modified time alone
rval = SetFileTime(hFile, ctime, atime, wtime)
End If
'Close File Handle
rval = CloseHandle(hFile)
End
End Sub

Download this snippet    Add to My Saved Code

'Set the File modified time to Current System Time using GetSystemTimeAsFileTime API Comments

No comments have been posted about 'Set the File modified time to Current System Time using GetSystemTimeAsFileTime API. Why not be the first to post a comment about 'Set the File modified time to Current System Time using GetSystemTimeAsFileTime API.

Post your comment

Subject:
Message:
0/1000 characters