VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



'Set filetime using SetFileTime 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 filetime using SetFileTime 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 Function LocalFileTimeToFileTime Lib "kernel32" (lpLocalFileTime As FILETIME, lpFileTime As FILETIME) As Long
Private Declare Function SystemTimeToFileTime Lib "kernel32" (lpSystemTime As SYSTEMTIME, lpFileTime As FILETIME) 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 'Set filetime using SetFileTime 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 writng
hFile = OpenFile("c:\waste.txt", buff, OF_WRITE)
If hFile Then
ftime.wDay = 26: ftime.wMonth = 3: ftime.wYear = 1987
ftime.wHour = 11: ftime.wMinute = 23: ftime.wSecond = 45
'Convert the time in System Format to File Format
rval = SystemTimeToFileTime(ftime, wtime)
'Convert the Local File Time Zone to Greewich Time Zone
rval = LocalFileTimeToFileTime(wtime, wtime)
'Set Modified time alone
rval = SetFileTime(hFile, ctime, atime, wtime)
End If
'Close the File Handle
rval = CloseHandle(hFile)
End
End Sub

Download this snippet    Add to My Saved Code

'Set filetime using SetFileTime API Comments

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

Post your comment

Subject:
Message:
0/1000 characters