Last Name                                                                First Name

Date                                                                           Class Night

CIS 170 - Microcomputer Operating Systems

Professor. Edward F. Bouling, IV

Replaceable Parameters

With the majority of DOS commands, what you type after the command name is considered to be a command parameter. The command parameter is what the command will manipulate.

In addition DOS commands are flexible enough to allow you to change the command parameter to whatever you need it to be.


Prompt Command Command parameter 1 Command parameter 2
C:\> Dir A:  
C:\> Dir B:  
C:\> Dir C:\DOS  
C:\> copy File1 File2
C:\> copy File3 File4


You can build the same type of flexibility into batch files by using replaceable parameters. DOS has 10 replaceable parameters, %0, %1, %2, %3, %4....%9. The work in your batch file the same way they work in DOS commands. They work by position. When you execute the batch file, DOS replaces the replaceable parameter with whatever you typed in after the batch file name.

%0 is the first parameter but its only used to hold the name of the batch file. %1 is used as the first parameter for the batch file, %2 is the second parameter, so on, and so on.

The below batch file is supposed to print any file that you enter in as its first parameter.


copy %1 prn What happens here is that whatever is typed in after the batch file name replaces the %1, within the batch file, hence the name replaceable parameters.

C\:> prnt autoexec.bat

The filename autoexec.bat will replace the %1 in the command copy %1 prn within the batch file, so now autoexec.bat is sent to the printer.

C\:> prnt Config.sys

The filename Config.sys will replace the %1 in the command copy %1 prn within the batch file, so now Config.sys is sent to the printer.


Rem Author Alfred E. Newman


Rem Demonstrating using replaceable parameters

@echo off


echo The zero parameter is %0

echo The first parameter is %1

echo The second parameter is %2

echo The third parameter is %3

echo The fourth parameter is %4

echo The fifth parameter is %5

If you were to enter params eat at joes fine foods today at four. The zero parameter is params

The first parameter is eat

The second parameter is at

The third parameter is joes

The fourth parameter is fine

The fifth parameter is foods

Anything after the fifth parameter is ignored.

Lab exercises 1 and 2

Exercise 1

Create the above batch files and execute them, experiment with them to see how replaceable parameters work.

Exercise 2

Create a batch file that will

Clear the screen

Create the subdirectory colors within the other subdirectory (if you don't have an other subdirectory on your diskette make one)

Move you to the subdirectory colors.

Display the contents of the subdirectory colors.

Name the batch file Newdir.bat

Now make the Newdir.bat flexible enough so that you can create a directory (with any name you want) within the other subdirectory, and then be automatically moved to the newly created directory.

  Make a copy for yourself and a copy to give me.