Purpose:Change a file's time stamps, and optionally create a file

 

Format:TOUCH [/A:[[-][+]rhsdaecjot] /C /CD [/D[acw][date] /E /F /I""text"" /N /O:[-]acdeginorstuz /Q /R[:acw] file /S[[+]n] /T[acw[u]][hh:mm[:ss[.dd]]] file...

 

fileOne or more files whose date and/or time stamps are to be changed.

 

/A:

Attribute select

/N

No action

/C

Create file

/O:

Order

/CD

Create directory

/Q

Quiet

/D

Date

/R

Reference file

/E

No error messages

/S

Subdirectories

/F

Force read-only files

/T

Time

/I

Match descriptions


 

 

File Selection:

 

Supports attribute switches, extended wildcards, ranges, multiple file names, subdirectories, catalog files, and include lists.

 

Usage:

 

TOUCH is used to change the date and / or time of a file. You can use it to be sure that particular files are included or excluded from an internal command, backup program, compiler MAKE utility, or other program that selects files based on their time and date stamps, or to set a group of files to the same date and time for consistency.

 

TOUCH should be used with caution, and in most cases should only be used on files you create. Many programs depend on file dates and times to perform their work properly. In addition, many software manufacturers use file dates and times to signify version numbers. Indiscriminate changes to date and time stamps can lead to confusion or incorrect behavior of other software.

 

By default, TOUCH affects only files. You must utilize the /A: option to include directories. /A:D will select directories only.

 

TOUCH sets three internal variables:

 

%_touch_dirsThe number of directories touched
%_touch_filesThe number of files touched
%_touch_errorsThe number of errors

 

Examples:

 

Change the last write date/time on the file testfile.txt to the current date/time:

 

touch testfile.txt

 

Change the creation date/time on the file testfile.txt to January 1, 2022 at 12:01am:

 

touch /dc2022-01-01 /tc00:01 testfile.txt

 

Options:

 

/A:Select only those files that have the specified attribute(s) set. See Attribute Switches for information on the attributes which can follow /A:.

 

You can specify /A:= to display a dialog to help you set individual attributes.

 

/CCreate file (as a zero-byte file) if it does not already exist. You cannot use wildcards with /C, but you can create multiple files by listing them individually on the command line.

 

/CDCreate the specified directory if it does not already exist.

 

/DIf neither /R nor /D are specified, the current date is used. If the /D option is specified without date, TOUCH will not modify the date even if /R is also specified. If the /D option is followed by date, and /R is not specified, date is used. The date must not be quoted. If both /R and /D with date are specified, the one specified later in the command takes effect.
       

On an LFN drive, you can specify which of the date fields should be set by appending a, c, or w to the /D option:

 

aLast access date
cCreation date
wLast modification (write) date

 

If you append a u to the date field, TOUCH will set the UTC date rather than the local date.

 

/ESuppress all non-fatal error messages, such as "File not found."  Fatal error messages, such as "Drive not ready," will still be displayed. This option is most useful in batch files.

 

/FThe file systems normally do not permit changing timestamps of read only files. The /F option forces date and time change of read-only files by temporarily removing the read only attribute.

 

/I"text"Select files by matching text in their descriptions. See Description Ranges for details.

 

/NDisplay what would occur without actually doing it.

 

/O:...Sort the files before processing. You may use any combination of the sorting options below. If multiple options are used, the listing will be sorted with the first sort option as the primary key, the next as the secondary key, and so on:

 

nSort by filename and extension, unless e is explicitly included. This is the default.
-Reverse the sort order for the next sort key
aSort names and extensions in standard ASCII order, instead of numerically when numeric substrings are included in the name or extension.
cSort by compression ratio
dSort by date and time (oldest first); also see /T:acw
eSort by extension
gGroup subdirectories first, then files
iSort by description
oSort by owner
rReverse the sort order for all options
sSort by size
tSame as d
uUnsorted
zSame as s

 

/QDo not display normal messages.

 

/RThe /R option permits duplication of the time stamp of ref_file (which must immediately follow the /R, and can be a file or subdirectory). For example, if you recompile an old program (e.g., to obtain an intermediate file that has long been deleted) you may want to use the timestamp of the source file that was last changed as the time stamp of the newly built duplicate of the original object file to prevent a "make" from attempting to rebuild everything else in the project as shown in the example:

 

touch /r project.c project.obj

 

Another use could be to synchronize files without rendering the current version inaccessible during the synchronization:

 

touch /c /r c:\jpsoft\tcmd.pdf %temp\tcmd.pdf

copy /u ftp://ftp.jpsoft.com/help/tcmd.pdf %temp\tcmd.pdf

 

In the above example TOUCH creates an empty file with the time stamp of your already existing help file; COPY updates the empty file if a newer version is available (beware of time stamp synchronization across the Internet!).

 

On an LFN drive, you can specify which of the date/time fields should be used by appending a, c, or w to the /R option:

 

aLast access date and time (on VFAT volumes access time is always midnight).
cCreation date and time
wLast modification (write) date and time

 

/STOUCH all matching files in the specified directory and its subdirectories. Do not use /S with @file lists. See @file lists for details.

 

If you specify a number after the /S, TOUCH will limit the subdirectory recursion to that number. For example, if you have a directory tree "\a\b\c\d\e", /S2 will only affect the "a", "b", and "c" directories.

 

If you specify a + followed by a number after the /S, TOUCH will not modify any time stamps until it gets to that depth in the subdirectory tree. For example, if you have a directory tree \a\b\c\d\e, /S+2 will not modify anything in \a or \a\b.

 

/TIf neither /R nor /T are specified, the current time is used. If the /T option is specified without time, TOUCH will not modify the time even if /R is also specified. If the /T option is followed by time, and /R is not specified, time is used. (Time must not be quoted). If both /R and /T with time are specified, the one specified later in the command takes effect.
 
On an LFN drive, you can specify which of the time fields should be set by appending a, c, or w to the /T option:

 

aLast access time (on VFAT volumes access time is always midnight).
cCreation time
wLast modification (write) time

 

If you append a u to the time field, TOUCH will set the UTC time rather than the local time.