Sets the date and time that a file was created, accessed and modified
#include <Date.au3>
_Date_Time_SetFileTime ( $hFile, $pCreateTime, $pLastAccess, $pLastWrite )
| $hFile | Handle to the file. The file handle must have been created using the CreateFile function with the FILE_WRITE_ATTRIBUTES access right. |
| $pCreateTime | Pointer to a $tagFILETIME structure that contains the new date and time the file was created. This be 0 if the application does not need to set this information. |
| $pLastAccess | Pointer to a $tagFILETIME structure that contains the new date and time the file was last accessed. The last access time includes the last time the file was written to, read from, or (in the case of executable files) run. This can be 0 if the application does not need to set this information. To preserve the existing last access time for a file even after accessing a file, call SetFileTime with this parameter set to -1 before closing the file handle. |
| $pLastWrite | Pointer to a $tagFILETIME structure that contains the new date and time the file was last written to. This can be 0 if the application does not want to set this information. |
| Success: | True |
| Failure: | False |
#include <Date.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
Global $g_idMemo
Example()
Func Example()
Local $hFile, $tFile, $aTime
; Create GUI
GUICreate("Time", 400, 300)
$g_idMemo = GUICtrlCreateEdit("", 2, 2, 396, 296, $WS_VSCROLL)
GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
GUISetState(@SW_SHOW)
; Create test file and set file times
$hFile = _WinAPI_CreateFile(@ScriptDir & "\Test.xyz", 1)
If $hFile = 0 Then _WinAPI_ShowError("Unable to create file")
$tFile = _Date_Time_EncodeFileTime(@MON, @MDAY, @YEAR, @HOUR, @MIN, @SEC)
Local $pFile = DllStructGetPtr($tFile)
_Date_Time_SetFileTime($hFile, $pFile, $pFile, $pFile)
_WinAPI_CloseHandle($hFile)
; Read file times
$hFile = _WinAPI_CreateFile(@ScriptDir & "\Test.xyz", 2)
If $hFile = 0 Then _WinAPI_ShowError("Unable to open file")
$aTime = _Date_Time_GetFileTime($hFile)
_WinAPI_CloseHandle($hFile)
MemoWrite("Created ..: " & _Date_Time_FileTimeToStr($aTime[0]))
MemoWrite("Accessed .: " & _Date_Time_FileTimeToStr($aTime[1]))
MemoWrite("Modified .: " & _Date_Time_FileTimeToStr($aTime[2]))
; Loop until the user exits.
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
FileDelete(@ScriptDir & "\Test.xyz")
EndFunc ;==>Example
; Write a line to the memo control
Func MemoWrite($sMessage)
GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1)
EndFunc ;==>MemoWrite