JSI Tip 0494 - How to parse a batch parameter.

Jerold Schulman

April 14, 1998

1 Min Read
ITPro Today logo

When you invoke a batch file with a parameter (%1), you are able to parse it to extract meaningfull information (if Command Extension are enabled). See the following examples:

Parameter

D e s c r i p t i o n

 %1 

 The normal parameter. 

 %~f1 

 expands %1 to a fully qualified path name. 

 %~d1 

 expands %1 to a drive letter only. 

 %~p1 

 expands %1 to a path only. 

 %~n1 

 expands %1 to a file name only (prefix) 

 %~x1 

 expands %1 to a file extension only. 

 %~s1 

 changes the meaning of n and x options to reference the short name. 

 %~z1 

 Returns the size of the file, if %1 is a file. 

 %~a1 

 Returns the attributes of the %1 object. 

 %~t1 

 Returns the date and time that a file was modified, if %1 is a file. 

You can use some of these modifiers in combination:

Parameter

D e s c r i p t i o n

 %~dp1 

 expands %1 to a drive letter and path only. 

 %~nx1 

 expands %1 to a file name and extension only. 

See tips 523, 273, and 3579.



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like