Reference:
How to use this Batch Reference Session
Reference
Using this page
Terms in or and symbols, all show more details on demand:
, or any
term to see an
now)
click for details.You'll find this Reference in our Batch Course, too
Reference
Session index
In this Batch file Reference Session:
For more than Reference try our tutorials instead
Tutorials Our free Batch Course (which has this Reference built in) teaches the syntax of Batch files thoroughly in 21 interactive Lessons. For fully-annotated example Batch files, see our Batch Library. Also see our Batch Troubleshooting tips.
Alphabetical List:
Before you read on
Alphabetical
Using this page
Don't forget that you can see extra information on demand:
, or any
term to see an Useful syntax examples
Batch commands have built-in help, for example:
Alphabetical Reference in List Box format
Alphabetical
List Box
Our Course Reference is in alphabetical List Box format at the top of this Session, and again here below. Use the alphabetical List Box when you know what commands you want to read about (otherwise see commands arranged in Functional Groups).
Choose and click
Choose a command or term from our Course Reference List Box, and click to read more.
Remember Our Course Reference supplements /? help, it doesn't replace it.
or a term in purple text. All these InfoBox notes are built into the page, so they work online or offline.
We use a distinctive, bold purple cue for InfoBox information where it's more appropriate than the
symbol. Either way, you'll know there are more details you can read whenever you want, simply by hovering your mouse over it. We normally gloss every occurrence of a term (except where it's in the left-margin side headings or a LookUp box)
Each instance of the
symbol will often disclose different information (where it's appropriate). The same term in purple always shows the same information, wherever on the page you find it (and we normally gloss every occurrence of a term, except where it's in the left-margin side headings or a LookUp box).
The same LookUp box window will be used by any clickable item on this page. More mouse clicks won't open extra windows, so you needn't bother to close a LookUp window yourself. When you leave this Session, any LookUp window you still have open will close.
MS-DOS (=the MicroSoft Disk Operating System) included Batch processing from version 1.0 (August 1981). It was added to help IBM engineers run long lists of commands to test MS-DOS on the IBM Personal Computer original prototype. The Batch language developed steadily through later versions of MS-DOS, and is always installed in Windows 95, 98, and ME (but many users don't know this).
, waits for you to type a new command. A command typed at the prompt executes as soon as you press the Return key.
When several windows are open, only one has focus (it has a standard dark blue Title bar). The window with focus is the one that receives any keystrokes from your keyboard. You give a window focus by clicking on it with the mouse (or clicking its Taskbar button). You can also use Alt Tab to put up a menu that will cycle the focus through all windows.
Our Batch Reference is built into our pages so it works both offline and online. Every time a Batch command or term (in dark blue) occurs in the text, you can click on it to see a pop-up box with details and examples. This same fast LookUp feature applies throughout each Lesson in our MS-DOS Batch Course.
Clicking a Batch command or technical term directly in this way shows the same information as using the Course Reference pull-down List Box.
In our Lessons, the Course Reference grows more detailed as you progress through the Course (to avoid too much detail too early). This Reference Session uses the full Course Reference (which appears in the Course at Lesson 20).
The path is where to find a file or folder on a disk or network. Always "quote" a path used with Batch commands if it contains Space s. Windows uses the backslash \ separator in paths (the forward slash / is used for switches). Don't confuse this sense of path as a pointer to a file or folder with the PATH command or PATH environment variable (which holds the list of paths that are searched for executable files).
If you're not sure how to type the pipe Functional groups:
Before you read on
By Function
Using this page
Don't forget that you can see extra information on demand:

Find your command and click on it to read more
By Function
Clickable
The Batch commands/terms that we cover are here by function. As usual, each term in is for more details and syntax examples (see our List Box if you already know the command you want):
Batch commands fall into two main types
Batch commands are either (coded within or ) or (each coded in a program file of its own). We use upper case for commands, such as , and lower case for commands, such as . This is our convention,
Many commands return s a Batch file can test. In Windows 95/98/ME, commands do not return s.
Delays and waits:
Before you read on
Delays / waits
Using this page
Don't forget that you can see extra information on demand:
, or any
term to see an Delays and waiting for external events
Delays / waits
Fixed-time
Process wait
Event wait
We look at three situations:
Fixed-time: Pause a Batch file for a fixed time, say 10 seconds, or an hour
Process wait: A Batch file runs a process, and waits for it to finish
Event wait: A Batch file controls several others, and needs to wait for them to finish
1 Fixed-time delays:
Pausing for a set time
Delays / waits
Fixed-time
with choice
with ping
It's often convenient to pause execution of a Batch file for a fixed time, then continue. You can't use the command because it waits until the user presses a key. However, you can pause a batch file for a fixed time with choice or with ping .
1.1 Fixed-time delays:
With command
Delays / waits
Fixed-time
with choice
A common way to insert a fixed-time delay of 1–99 seconds is by using . This can be used in Windows 95/98/ME. In you may need to install the command (if you click
there's a download link at item (e) - but see the delay method, too, before you decide to download).
Using for delays from 1–99 seconds
For Windows 95/98/ME, and a delay of, say 10 seconds, you can use:
REM | choice /c:delay /td,10>NUL
In , works differently, so use a instead:
TYPE NUL | choice /c:delay /td,10 >NUL
Note There is a Space before the to , shown highlighted. A digit placed just before the operator in may conflict with of and (which uses the syntax 1> and 2> respectively). This second version also works in Windows 95/98/ME, so can be used for both Operating systems.
Our Batch Course explains this method
In either case, replace the 10 with any number from 1–99 for other delays (in seconds). Our Batch Course Lesson 10 (more in Lesson 20) explains the method in detail.
Interruption to delay by Ctrl C
Delays / waits
Fixed-time
with choice
trap Ctrl-C
In Windows 95/98/ME, a user can interrupt a delay with Ctrl C to frustrate it. However, a batch file can check whether or not it was interrupted. The command:
TYPE NUL | choice /c:delay /td,10 >NUL
returns 1 if the delay completes, because the /td,10 switch supplies a 10-second timeout reply of d, the 1st in the c:delay reply list (the other replies, elay, aren't used: they're added simply to document the command).
However, if the user cuts the delay by pressing Ctrl C and answering N (to the usual Terminate batch job (Y/N)? question) the command returns 0.
Batch file traps Ctrl C delay interruption
Delays / waits
Fixed-time
with choice
trap Ctrl-C
example
The following example shows the syntax to detect a user shortening the delay with Ctrl C then answering N (which resumes the batch job).
Use the test to take appropriate action if a delay is interrupted.
Our Batch Course has much more detail
If you're uncertain about how to use , or the test, or the right order in which to test s, take our Batch Course for a thorough treatment.
1.2 Fixed-time delays:
Before you read on
Delays / waits
Using this page
Don't forget that you can see extra information on demand:
, or any
term to see an Fixed-time delays with the ping command
Delays / waits
Fixed-time
with ping
The command is part of the standard Microsoft TCP/IP setup, and so it's available on all Windows internet-enabled PCs. sends a diagnostic request to a remote server and waits for an echo. It has a to set the number of requests to send.
For example, to send 11 requests, use: ping -n 11 (and add the destination server).
sends the first request immediately. When it gets a reply, or times out (because the remote server doesn't reply), it waits one second and then sends the next request.
Sending requests to your own machine
Your own machine (Local Host) has the TCP/IP address 127.0.0.1 (by convention) and it always replies to a request immediately. So, for example, you can do this:
ping -n 11 127.0.0.1
sends the first request and it gets a reply immediately. waits one second, sends the next request, gets an immediate reply, and so on – for the ten requests after the first. So to the Local Host those 11 times takes exactly 10 seconds.
You needn't be online to ping yourself
You can yourself (127.0.0.1) offline; and like the planet
If we add a to to suppress the reports, the command is complete:
Delays / waits
Fixed-time
with ping
examples
Note The Space before the >NUL avoids any conflict with
Ping delays use very little CPU time
Unlike delays, which are processor intensive and may slow other programs, a delay uses little CPU (Central Processor Unit) time (typically less than 0.5%).
Interruption to ping delay by Ctrl C
Delays / waits
Fixed-time
with ping
trap Ctrl-C
A user can interrupt a delay with Ctrl C to frustrate it. However, a batch file can check whether or not it was interrupted. The command:
ping -n 601 127.0.0.1 >NUL
returns 0 when the 10 minute=(601-1 seconds) delay finishes.
However, if the user cuts the delay by pressing Ctrl C (and resumes by answering N to any Terminate batch job (Y/N)? question) the command returns:
Batch file traps Ctrl C delay interruption
Delays / waits
Fixed-time
with ping
trap Ctrl-C
example
The following example shows the syntax to detect a user shortening the delay with Ctrl C (then answering any Terminate question N , to resume batch job).
Use the test to take appropriate action when a delay is interrupted.
Our Batch Course has much more detail
If you're uncertain about how to use the test, or the right order in which to test s, take our Batch Course for a thorough treatment.
2: Wait for a process
Before you read on
Delays / waits
Using this page
Don't forget that you can see extra information on demand:
, or any
term to see an With command
Delays / waits
Process wait
with start
When a Batch file executes a program, Windows runs it as a separate process in parallel with the Batch file. The Batch file continues with the next line of code, before the program finishes. If the Batch file needs the result of the program, it must wait. Instead of (guessing) a fixed delay, you can use the command.
/wait waits and returns s
The /wait pauses a Batch file until a ed program finishes. What's more, if you run a program with /wait, the command will return any (from the program) to your Batch file. To see a list of that supports, use start /? (in Windows has extra features).
Example:
Note 1 You can add and parameters for the program (if it uses them). Separate each with a Space as shown or won't handle it correctly.
Note 2 The /wait switch can usually be abbreviated to /w.
Windows NT/2000/XP with "quoted" path
Delays / waits
Process wait
with start
If the program has a long with Space s, you'll need to "quote" it. But in Windows , treats the first quoted parameter as a window title, so you need a quoted string before any quoted (it can be an empty " " dummy string).
Windows 95/98/ME with "quoted" path
Again, if the program has a long with Space s, you'll need to "quote" it. The Windows 95/98/ME command doesn't accept a window title, so don't use one.
Cross-platform tweak:
Handle "quoted" path
Delays / waits
Process wait
with start
quote tweak
The same quoted command can work in both Windows and Windows 95/98/ME, with a special tweak. This is a command to a title string only in Windows (but does nothing in Windows 95/98/ME).
A need not be at the end of a line
In Windows 95/98/ME, the statement:
ECHO/>NUL&SET TITLE=""
that's just a pair of empty "double-quotes".
simply s the string &SET TITLE="" to . It's a peculiarity of that the >NUL applies to the whole line, even when it isn't at the end of the command. The use of ECHO/ has fewer side effects than other suffix characters, so we use it in special situations instead of ECHO. (click
for details of all suffix characters).
In Windows NT/2000/XP there are two commands
In Windows , & separates commands, so sees two of them:
ECHO/>NUL and the & -separated SET TITLE=""
The ECHO/>NUL simply s a carriage return and linefeed to , and the statement is executed, loading the window title in the variable TITLE. As a result, the TITLE variable is to a window title only in Windows .
Putting this together in a Batch file fragment
Delays / waits
Process wait
with start
quote tweak
example
As a result, the syntax below works for both Windows 95/98/ME and :
Note 1 SET TITLE= (without a value) ensures TITLE is clear in Windows 95/98/ME.
Note 2 In the line,
Note 3 In the line, we expand the TITLE variable. In Windows 95/98/ME it expands to nothing, but in Windows it expands to a pair of "quotes". If you're uncertain about expanding variables, see Lesson 1 of our Batch Course.
Practical example:
Using UltraEdit
Delays / waits
Process wait
with start
example
The Hex Editor UltraEdit can be run from a Batch file. Here, we it with a command line that runs a Macro (edit.mac) 100 times and Exits when finished:
Waiting for a complex hex edit to complete
@ECHO OFF
Batch file waits until external edit complete
The macro repetition may well take several seconds, so the Batch file must wait before ing the resulting file. The /wait ensures that it does. The command looks up the UltraEdit in the Windows registry (in the App paths key), so there is no need for a quoted "Program Files" in this case.
Some multi-threaded programs don't /wait
Some programs are multi-threaded: they spawn child processes (threads). It's possible that the /wait command may resume before all threads of this type of program are finished. In those (and other) cases, a Batch file can wait for an event.
3: Wait for an event:
Before you read on
Delays / waits
Using this page
Don't forget that you can see extra information on demand:
, or any
term to see an Big projects are best split into many files
Delays / waits
Event wait
A large Batch project is best split between a number of Batch files, in a hierarchy with one Master Batch file in control of the others. It's the others that do all the actual work.
With the Master file loses control
The Master Batch file could each of the other batch files in turn, but this puts each ed file in control. The Master file must wait until each ed file finishes before ing the next. If one of the other batch files hangs, everything stops from that point.
Master file s job and waits for events
To stay in control, the Master Batch file s the others (without the /wait switch, or it would be waiting as it does with ). The other files now run in parallel, while the Master file checks for specific events in the other files, and reports on any problems. A common event is that one of the other files has finished.
Waiting for an event
– the theory
Delays / waits
Event wait
theory
Suppose a Master Batch file has ed another batch file (OtherBatch.bat), and needs to wait until it's finished before some other task can be run. The solution is:
Note Transient files such as _FLAG.TMP are best created in the folder, but for this discussion, we'll ignore that refinement. If you're unfamiliar with this folder, 
Waiting for an event
– the practice
Delays / waits
Event wait
practice
Many things can go wrong in practice. Consider some problems (and their solutions):
An example with those problems handled
Delays / waits
Event wait
example
Here is a pair of example Batch files coded with those solutions. The superscripts show where the problems numbered 1–4 above are handled.
Master.bat code:
1 Make sure doesn't exist already
2 Use name specific to OtherBatch.bat, 4and pass as command line parameter
3 Wait long enough, then assume a problem in OtherBatch.bat
OtherBatch is given the Flagfile name to use
Delays / waits
Event wait
example
OtherBatch.bat is written to receive its name as a command-line parameter. It tests that it has received a parameter, and that it isn't the name of an existing file.
OtherBatch.bat code:
4 Use name passed in command-line parameter %1, so that the name isn't into OtherBatch.bat. Passing data as parameters makes it easier to edit and maintain a suite of batch files.
Note See Lesson 12 of our Batch Course for how to use command-line parameters.
Short names
Using this page
Short-form names:
Before you read on
Don't forget that you can see extra information on demand:
, or any
term to see an Finding the full short-form name of a file
Short names
When you want the full (short name) to a file in nested long-named folders, such as:
With the file won't be executed by accident
Note You can also use this method with a folder to find its name, say to use as a . Just drag-and-drop the folder from Explorer on to the
Avoid mistakes with
Copy the short-form to a file using the window buttons:
Network paths:
Before you read on
Network paths
Using this page
Don't forget that you can see extra information on demand:
, or any
term to see an Drag-and-drop method works across networks
Network paths
Drag-and-drop will find network to remote files. Locate the remote file in Explorer (Network Neighborhood), and drag-and-drop it on an
Avoid mistakes with
Copy the network to a file using the window buttons:
Typical example of UNC name used with
Suppose a remote machine's network name is OTHER, and its C: drive is mapped to C (which is normal). The example below uses the /L=(List only) and
Using to check files across a network
Network paths
example
Updating changed files across a network
Without the /L=(List only) , the example above would update the local files by copying any new or changed versions from the remote machine; files that haven't changed aren't copied. For more details of how works,
anywhere in this Session or in our Batch Course.
Remember Our Course Reference supplements the /? help, it doesn't replace it. In
Batch documentation:
Before you read on
Comments
Using this page
Don't forget that you can see extra information on demand:
, or any
term to see an The most useful (but underused) commands
Comments
REM and ::
You can put s in Batch files: these are ignored when your Batch files run.
We our Batch files extensively (see examples in our Batch Library). We find it saves time when later changing them. You can read the difference between the two introducers by clicking on
or
(double-colon, most often used).
s used in immediate mode
Most Batch commands can be used at the : this is called immediate mode. If you type a at the , nothing happens:
For an example using in immediate mode, see how to
On-screen help:
Before you read on
Using this page
Don't forget that you can see extra information on demand:
, or any
term to see an Getting help with /?
Quick to use
Most
/? is quick and easy and there's often
Here at Allenware.com, we still use /? help to check some command syntax details, because it's quick, easy, and it's always right there at the when you need it. If you find that /? help scrolls off screen before you can read it all, use a to to read one screenful at a time. For example:
MS-DOS version 6.22:
Before you read on
Using this page
Remember, hover your mouse over any , or any term to see an .
Extensive help system
Installation
The Windows 95/98/ME CD-ROM includes the old
Once the files are copied, you can use the 6.22 help system. Just type
The 6.22 help system is very extensive, and although some of it no longer applies in Windows 95/98/ME, much remains useful. To close 6.22 help, press Alt-F X .
Further questions:
You can
If you have questions or comments about this Reference Session, please (your email subject line should contain: