# FileSetTime

Changes the datetime stamp of one or more files or folders. Wildcards are supported.

    FileSetTime , YYYYMMDDHH24MISS, FilePattern, WhichTime, OperateOnFolders?, Recurse?

## Parameters

YYYYMMDDHH24MISS

  If blank or omitted, it defaults to the current time. Otherwise, specify the time to use for the operation (see Remarks for the format). Years prior to 1601 are not supported.

  This parameter is an expression. Consequently, if multiple variables need to be concatenated to form a single timestamp, the dot operator should be used instead of percent signs. For example: `FileSetTime, Year . Month . Day, C:\My File.txt`.

FilePattern

  The name of a single file or folder, or a wildcard pattern such as C:\Temp\*.tmp. FilePattern is assumed to be in %A_WorkingDir% if an absolute path isn't specified.

  If omitted, the current file of the innermost enclosing File-Loop will be used instead.

WhichTime
  Which timestamp to set:
  M = Modification time (this is the default if the parameter is blank or omitted)
  C = Creation time
  A = Last access time
OperateOnFolders?

  0 (default) Folders are not operated upon (only files).
  1 All files and folders that match the wildcard pattern are operated upon.
  2 Only folders are operated upon (no files).

  Note: If FilePattern is a single folder rather than a wildcard pattern, it will always be operated upon regardless of this setting.

  This parameter can be an expression.

Recurse?

  0 (default) Subfolders are not recursed into.
  1 Subfolders are recursed into so that files and folders contained therein are operated upon if they match FilePattern. All subfolders will be recursed into, not just those whose names match FilePattern. However, files and folders with a complete path name longer than 259 characters are skipped over as though they do not exist. Such files are rare because normally, the operating system does not allow their creation.

  This parameter can be an expression.

## Error Handling

[v1.1.04+]: This command is able to throw an exception on failure. For more information, see Runtime Errors.

ErrorLevel is set to the number of files that failed to be changed or 0 otherwise. If the specified timestamp is invalid, or FilePattern resolves to a blank value, ErrorLevel is set to 1.

If files were found, A_LastError is set to 0 (zero) or the result of the operating system's GetLastError() function immediately after the last failure. Otherwise A_LastError contains an error code that might indicate why no files were found.

## Remarks

A file's last access time might not be as precise on FAT16 & FAT32 volumes as it is on NTFS volumes.

The elements of the YYYYMMDDHH24MISS format are:

YYYY | The 4-digit year
MM | The 2-digit month (01-12)
DD | The 2-digit day of the month (01-31)
HH24 | The 2-digit hour in 24-hour format (00-23). For example, 09 is 9am and 21 is 9pm.
MI | The 2-digit minutes (00-59)
SS | The 2-digit seconds (00-59)

If only a partial string is given for YYYYMMDDHH24MISS (e.g. 200403), any remaining element that has been omitted will be supplied with the following default values:

MM: Month 01
DD: Day 01
HH24: Hour 00
MI: Minute 00
SS: Second 00

The built-in variable A_Now contains the current local time in the above format. Similarly, A_NowUTC contains the current Coordinated Universal Time.

Note: Date-time values can be compared, added to, or subtracted from via EnvAdd and EnvSub. Also, it is best to not use greater-than or less-than to compare times unless they are both the same string length. This is because they would be compared as numbers; for example, 20040201 is always numerically less (but chronologically greater) than 200401010533. So instead use EnvSub to find out whether the amount of time between them is positive or negative.

## Related

FileGetTime, FileGetAttrib, FileSetAttrib, FileGetSize, FileGetVersion, FormatTime, File-loop, EnvAdd (date math), EnvSub (date difference)

## Examples

#1: Set the modification time to the current time for all matching files:

    FileSetTime, , C:\temp\*.txt

#2: Set the modification date (time will be midnight):

    FileSetTime, 20040122, C:\My Documents\test.doc

#3: Set the creation date. The time will be set to 4:55pm:

    FileSetTime, 200401221655, C:\My Documents\test.doc, C

#4: Change the mod-date of all files that match a pattern. Any matching folders will also be changed due to the last parameter:

    FileSetTime, 20040122165500, C:\Temp\*.*, M, 1