August 25, 2009

[cmd]Batch - Filename Parameter Extensions

"When a parameter is used to supply a filename then the following extended syntax can be applied:

we are using the variable %1 (but this works for any parameter)

%~f1 - expands %1 to a Fully qualified path name - C:\utils\MyFile.txt

%~d1 - expands %1 to a Drive letter only - C:

%~p1 - expands %1 to a Path only - \utils\

%~n1 - expands %1 to a file Name, or if only a path is present - the last folder in that path

%~x1 - expands %1 to a file eXtension only - .txt

%~s1 - changes the meaning of f, n and x to reference the Short name (see note below)

%~1 - expand %1 removing any surrounding quotes (")

%~a1 - display the file attributes of %1

%~t1 - display the date/time of %1

%~z1 - display the file size of %1

%~$PATH:1 - search the PATH environment variable and expand %1 to the fully qualified name of the first match found.

The modifiers above can be combined:

%~dp1 - expands %1 to a drive letter and path only

%~nx2 - expands %2 to a file name and extension only"

No comments:

Post a Comment