SetFileDate

Top  Previous  Next

 

The SetFileDate command allows you to set a selected Date value on the specified file. For example, you may wish to set the date the file was created, last accessed, or last modified to a new date.

 

Command Syntax

 

SetFileDate:[SourceFileName],[NewDate],[DateType],[DateFormat]

 

The colon after the command and the space between parameters are compulsory. Any additional spaces or characters will cause an error to be thrown. The command itself is not case sensitive, but parameters may be depending on the operating system and locale.

 

Parameters:

 

SourceFileName: The fully qualified path and file name identifying the file on which to modify the date

NewDate: The new date as a string in a recognised format or a format that you specify in the DateFormat parameter, see Date Format Strings for more information

DateType: A string representing a valid member of the FileDateType enumeration, currently one of the following values: CreationDate, LastAccessDate, LastModifiedDate

DateFormat: An optional string representing a Date Format to be used to convert the script value to a DateTime object. Most standard formats will be recognised automatically, but if you have a date in an unusual format you can use this parameter to tell the system how to create a date from the value. This is particularly useful when the NewDate property is retrieved from an external source such as a database and stored as a variable rather than being explicitly specified as part of the script item.

 

All parameters other than DateFormat are compulsory. If any parameter other than DateFormat is missing or invalid an error will be thrown. The parameters must be surrounded by quotation marks if one or more spaces are included in the parameter value. It is good practice to include the quotation marks in any case, so that it reduces the risk of error when writing scripts.

 

Examples:

 

A date value in a known standard format so no format specifier required:

 

SetFileDate:"C:\Test Text.txt","01/01/2024","LastModifiedDate"

 

A date value in an unusual format, for example a value retrieved from a database or another source known to be in a particular format:

 

SetFileDate:"C:\Test Text.txt",%%DateFromSource%%,"LastModifiedDate","MM/dd/yy H:mm:ss zzz"

 

See Also: Date Format Strings Conditional CopyFile DeleteFile MoveFile RenameFile