Child pages
  • Windows .cmd script hints
Skip to end of metadata
Go to start of metadata

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.

%~1Expands %1, removes surrounding quotes (") 
%~f1Expands %1 to a fully qualified pathname 
%~d1Expands %1 to a drive letter only 
%~p1Expands %1 to a path only 
%~n1Expands %1 to a filename only 
%~x1Expands %1 to a file extension only 
%~s1Changes the meaning of n and x options to reference the short name instead. 
%~$PATH:1Searches 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. 
%~a1Expands %1 to the file's attributes 
%~t1Expands %1 to the file's date/time 
%~zlExpands %1 to the file's size 

Feel free to play with my sandbox script petest.cmd

 


From: IBCL BLog.
Originally posted: 2009-01-16

  • No labels