TOUCH (Windows 2000 Resource Kit)

Change file timestamps

Syntax
      TOUCH [option]... files ...

Key
   /t year month day hour minute second

This is a POSIX utility.

Use the optional argument /t to specify a date other than the current time.
( four-digit years, two-digit months, days, hours, minutes, seconds)

An alternative Touch using the COPY command.

As first documented in the ancient (MSDOS) KB article Q69581 the COPY /b command can be used to touch the date/time of a file:

COPY /B Source.txt+,,Source.txt

This takes a source file, adds nothing (represented by the commas) and copies it to the same file as a destination. If you are working in a single folder, the second filename can be omitted as it will default to writing the same filename.

or as a batch file:

@Echo Off
COPY /B %1+,, %1

There are a few caveats with this technique:
It fails for read-only or hidden files.
It may reset file permissions back to the default for the folder.
In some versions of Windows, if the file is 0 bytes long it will be deleted!
If the file is a binary file with trailing null characters (0x00), they will be deleted, corrupting the file.
It is no longer a documented option in current versions of Windows.

A better alternative is PowerShell, you can call a one-line script with powershell.exe

Examples

Set the date to 7:30 am 1st October 2022:

C:\> TOUCH /t 2022 10 01 07 30 00 MyFile.txt

#And smiles you'll give and tears you'll cry
And all you touch and all you see
Is all your life will ever be# ~ Pink Floyd (Breathe)

Related commands

Q299648 - Date and Time Stamps for Files and Folders (FAT vs NTFS)
COPY - Copy one or more files to another location.
Equivalent PowerShell Script: touch - Change file timestamps.
Equivalent bash command (Linux): touch - Change file timestamps.


 
Copyright © 1999-2024 SS64.com
Some rights reserved