Special syntax for CMD compatibility

For compatibility with CMD, TCC supports additional syntax to qualify references to parameters of batch files and the control variable of the FOR command when referenced by the command it executes. However, this syntax can usually be replaced by more flexible Variable Functions.

 

CMD syntax

Expands to

Suggested replacement

%*

All parameters

%$

%~n

unquoted (")

%@replace[^",,%n]

%~fn

Fully qualified name of %n

%@full[%n]

%~dn

Drive letter portion of %n

%@left[2,%@full[%n]]

%~pn

Full path (no drive letter) of %n

%@right[-2,%@path[%@full[%n]]]

%~nn

Root name (no extension) of %n

%@name[%n]

%~xn

File extension of %n

.%@ext[%n]

%~sn

Fully qualified short name of %n

%@sfn[%n]

%~an

File attributes of %n

%@attrib[%n]

%~tn

File date and time of %n

%@filedate[%n] %@filetime[%n]

%~zn

File size of %n, bytes

%@filesize[%n]

%~$PATH:n

Full name of the first match for %n in %PATH

%@search[%n]

 

Notes

 

In the special case where the parameter to a %~ variable is 0, e.g., %~f0, the returned file name will always include the extension, as it does under CMD.

 

%~$PATH:n returns an empty string if the file %n is not found in the path.

 

References qualified by the tilde ~ trigger an error message when used improperly, e.g. if attempting to display the size of a string parameter which is not the name of a file.