Command Line


Use keywords to find the content you
are looking for with in the site.

Replaceable Parameters

Batch programs can be passed parameters on the command line. These parameters can be referenced by using replaceable parameters. There are a maximum of 10 replaceable parameters allowed, specified by %0 through to %9 inside a batch program and the special cases %# which returns the number of parameters passed to the batch program, %* which returns the batch programs original command line tail and %~ which is a modifier. The ~ modifiers have the following syntax :-


      ~remove any surrounding double quotes (ie. “).
      ~areturn the file attributes.
      ~dreturn the drive letter only.
      ~freturn the fully qualified path name.
      ~nreturn the file name only.
      ~preturn the path only.
      ~sthe path returned contains short names only.
      ~treturn the date/time of file.
      ~xreturn the file extension only.
      ~zreturn the size of file.
      ~$env:search the directories listed in the environment variable and return the fully qualified name of the first one found. If the environment variable name is not defined or the file is not found by the search, then an empty string is returned.
      numthe replaceable batch parameter 0 to 9

Modifiers can be combined to get compound results, for example :-

    %~dp2return the drive letter and path only for parameter %2.
    %~nx1return the file name and extension only for paratemeter %1.
    %~dp$PATH:3searches the directories listed in the PATH environment variable and return the drive letter and path of the first one found for parameter %3.
    %~ftza0return the DIR like output line for parameter %0.

There is no particular order the modifers need to be specified. env can be any valid environment variable, such as the PATH envirnoment variable. The ~ modifiers can not be used with %*.

For example, consider the batch program below called PARAMS.BAT. This batch program displays the total number of parameters, along with the first 10 parameters passed to the batch program with the double quotes removed from each parameter :-

    ECHO %%* is %*
    ECHO %%# is %#

    LET num=0
    FOR %%i in (%~0,%~1,%~2,%~3,%~4,%~5,%~6,%~7,%~8,%~9) do {

      ECHO %%%num% is %%i
      LET num=%num% + 1

Running the above batch program from the WinOne® prompt :-

    PARAMS “““abc””” 123

will display the following :-

    %* is “““abc””” 123
    %# is 2

    %0 is PARAMS
    %1 is abc
    %2 is 123

Copyright © 1995-2018 Lucien Cinc, All Rights Reserved
WinOne® is an Australian registered trademark

Go to the Australian Command Line Software web site.