Windows .cmd script hints
Ensuring command extensions are active
set DUMMY=Dummy
if not !DUMMY!==Dummy cmd.exe /e:on /v:on /c %0 %1 %2 %3 %4 %5 %6 %7 %8 %9
if not !DUMMY!==Dummy goto end
rem do much work
:end
Parameter %0-%9 and variable %foo expansion functions
Most of these ~ functions can be combined.
%~1 | Expands %1, removes surrounding quotes (") | |
%~f1 | Expands %1 to a fully qualified pathname | |
%~d1 | Expands %1 to a drive letter only | |
%~p1 | Expands %1 to a path only | |
%~n1 | Expands %1 to a filename only | |
%~x1 | Expands %1 to a file extension only | |
%~s1 | Changes the meaning of n and x options to reference the short name instead. | |
%~$PATH:1 | Searches the directories listed in the PATH environment variable and expands %1 to the fully qualified name of the first one found or empty string if nothing found. | |
%~a1 | Expands %1 to the file's attributes | |
%~t1 | Expands %1 to the file's date/time | |
%~zl | Expands %1 to the file's size |
Feel free to play with my sandbox script petest.cmd.
From: IBCL BLog.
Originally posted: 2009-01-16