Function FileSetTime

Function Reference


FileSetTime

Sets the timestamp of one of more files.

FileSetTime ( "file pattern", "time" [, type = 0 [, recurse = 0]] )

Parameters

file pattern The path of the file(s) to set, e.g. C:\*.au3, C:\Dir. (* and ? wildcards accepted - See Remarks)
time The new time to set in the format "YYYYMMDDHHMMSS" (Year, month, day, hours (24hr clock), seconds). If the time is blank "" then the current time is used.
type [optional] The timestamp to change:
    $FT_MODIFIED (0) = Last modified (default)
    $FT_CREATED (1) = Created
    $FT_ACCESSED (2) = Last accessed

Constants are defined in FileConstants.au3
recurse [optional]
    $FT_NONRECURSIVE (0) - no recursion (Default).
    $FT_RECURSIVE (1) - directories are recursed into.

Constants are defined in FileConstants.au3

Return Value

Success: 1.
Failure: 0 if error changing timestamp(s).

Remarks

See FileFindFirstFile() for a discussion about wildcards.

Using a date earlier than 1980-01-01 will have no effect.
Trying to change a timestamp on read-only files will result in an error.

Related

FileGetAttrib, FileGetTime, FileSetAttrib

Example

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>

Example()

Func Example()
    ; Create a constant variable in Local scope of the filepath that will be read/written to.
    Local Const $sFilePath = _WinAPI_GetTempFileName(@TempDir)

    ; Create a temporary file to read data from.
    If Not FileWrite($sFilePath, "This is an example of using FileSetTime.") Then
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.")
        Return False
    EndIf

    ; Set the modified timestamp of the file to 1st Nov 2003 and use the current time.
    Local $iFileSetTime = FileSetTime($sFilePath, "20031101", $FT_MODIFIED)

    ; Display the modified timestamp of the file and return as a string in the format YYYYMMDDHHMMSS.
    If $iFileSetTime Then
        MsgBox($MB_SYSTEMMODAL, "", "Timestamp:" & @CRLF & FileGetTime($sFilePath, $FT_MODIFIED, 1))
    Else
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst setting the timestamp of the file.")
    EndIf

    ; Delete the temporary file.
    FileDelete($sFilePath)
EndFunc   ;==>Example