Information on batch files

Batch fileBatch files allow MS-DOS and Microsoft Windows users to write a series of commands to run in order upon their execution for automating frequently performed tasks. For example, a batch file could be used to run frequently utilized commands, delete or move a series of files, and other jobs. Someone who is more familiar with Windows or Mac OS could think of a batch file as an icon on either operating system; which opens a program upon double-clicking.

Another common example of a batch file is the autoexec.bat, which is a boot batch file loaded each time the computer started MS-DOS and early versions of Windows. A simple batch file does not require any special programming skills and can be created by users with a basic understanding of MS-DOS commands.

Quick links

Creating a batch file
Batch commands
Batch file examples
Technical support
Debug Routines

Creating a batch file

MS-DOS users
Microsoft Windows and other users

MS-DOS users

To create a basic batch file in MS-DOS, follow the steps below.

  1. Open an MS-DOS command window or load MS-DOS.
  2. In the MS-DOS prompt, type: edit test.bat and press enter.
  3. If typed correctly, you should now be in a blue screen. Within the screen, type:
  4. pause
    dir c:\windows
    dir c:\windows\system

  5. Once these three lines have been typed in, click File and choose exit; when prompted to save, click Yes. Users who do not have a mouse cursor can accomplish this same task by pressing ALT+F to access the file menu, and then X to exit. Press Enter to save changes.
  6. Once you are back at the MS-DOS prompt, type: test and press Enter to execute the test.bat file. Because the first line is a pause, you will first be prompted to press a key. Upon doing so, the batch file runs line-by-line; in this case, listing the files in the Windows and Windows\system directories.

Tip: If you want to add more lines to this batch file, type edit test.bat to open the file for editing.

Additional information about the MS-DOS edit command can be found on our edit command page. Some versions of MS-DOS and bootable diskettes may not have the edit command. If this the case, you would either need to obtain the file or use the copy con command.

Microsoft Windows and other users

A Windows user may still utilize the previous steps for MS-DOS to create a batch file. If you are more comfortable with Microsoft Windows, you can use any text editor (such as Notepad or WordPad) to create your batch files; as long as the file extension ends with .bat. In the example below, we use the Windows Notepad to create a batch file.

  1. Click Start.
  2. Type: Notepad in the Run box and press Enter.
  3. Once Notepad is open, type the following lines or copy and paste them.
  4. @echo off
    echo Hello this a test batch file
    dir c:\windows

  5. Click File and then Save, and then navigate to where you want to save the file. For the file name, type "test.bat", and if your version of Windows has a "Save as type" option, choose "All files", otherwise it saves as a text file. Once you have completed these steps, click the Save button and exit notepad.
  6. To run the batch file, double-click it like any other program. Once the batch file has completed running it closes automatically.

Batch commands

Just like all MS-DOS commands, all batch file commands are not case sensitive. However, in the table below we have listed the batch file commands in all caps to help with identification.


Does not echo back the text after the at symbol. The @ is most often used as @ECHO OFF to prevent any of the commands in the batch file from being displayed, just the information needed.


The percent followed by a numeric value, beginning with one, allows users to add variables within a batch file. The below line is an example of what can be used in a batch file.

ECHO Hello %1

When the above one-line batch file is created, add your name after the batch file. For example, typing myname (being the name of the bat file) and then your name:

myname bob

would output:

Hello bob

Tip: You can keep going to %2, %3, and so on.


One of two ways of adding remarks into the batch file without displaying or executing that line when the batch file is run. Unlike REM, this line will not show regardless if ECHO off is in the batch file.


By adding a colon in front of a word, such as LABEL, you create a category, more commonly known as a label. A label allows you to skip to certain sections of a batch file such as the end of the batch file. Also see GOTO.


A call is used to run another batch file within a batch file. When the batch file that is called is completed, the remainder of the original batch file is completed. If the batch file does not exist, you'll get an error.


See running different programs for an example of how to use this command.

  • Additional information and the syntax of this command in each version of Windows and MS-DOS can be found on our CHOICE command page.

Just like the DOS command would clear your screen.

  • Additional information and the syntax of this command in each version of Windows and MS-DOS can be found on our CLS command page.

Will echo a message in the batch file. Such as ECHO Hello World prints Hello World on the screen when executed. However, without @ECHO OFF at the beginning of the batch file you'll also get "ECHO Hello World" and "Hello World." Finally, if you'd just like to create a blank line, type ECHO. adding the period at the end creates an empty line.


Exits out of the DOS window if the batch file is running from Windows.

  • Additional information and the syntax of this command in each version of Windows and MS-DOS can be found on our EXIT command page.

Used to go to a certain label, such as LABEL. An example of GOTO would be to GOTO END. For an example of this see running different programs.

  • Additional information and the syntax of this command in each version of Windows and MS-DOS can be found on our GOTO command page.

Used to check for a certain condition if the condition exists. If that condition exists it performs that function. To see an example of this see running different programs.

  • Additional information and the syntax of this command in each version of Windows and MS-DOS can be found on our IF command page.

Prompt the user to press any key to continue.


One of two ways of adding remarks into the batch file without displaying or executing that line when the batch file is run.


Changes the position of replaceable parameters in a batch program.


Used for Windows 95, Windows 98, and Windows NT 4.0 and above to start a Windows application; such as START C:\WINDOW\CALC would run the Windows Calculator. Users running Windows 3.x need to utilize the WIN command. For example, WIN C:\Windows\CALC.EXE would run Windows and then Calculator after Windows has finished loading.

Batch file examples

Running different programs
How to start Windows files and programs from a batch file
Creating a batch file delay
How to make a time log
More examples and support

Running different programs

Below is an example of how you can implement the choice options into your batch files. Each line in red may be omitted; they are there to explain certain sections of the batch file. Windows 2000 and Windows XP users need to substitute the choice command with the set command. See the set command page for additional help and information.

CHOICE /N /C:123 /M "PICK A NUMBER (1, 2, or 3)"%1

How to start Windows files and other programs from a batch file

To run Microsoft Windows programs or file, use the START command. The example below would run Windows Notepad.


You can also specify the direct location of the file by typing the following command.


*Windows users who have a different directory (e.g. Windows 2000 users) would need to substitute WINNT or the name of their directory in place of Windows in the above example.

The /m representing it to start the window Maximized. See the start command for further information.

Creating a batch file delay

Below is an example of how to delay a batch file anywhere from 5 to 99 seconds. In this example, we illustrate a five-second delay.


Additionally, you could use the sleep file found on our utility download section.

How to make a time log in a batch file

The example below demonstrates how to create a time log of when the batch file is loaded.


An alternate, slightly more complicated method that, to our knowledge, cannot be used in Windows NT, Windows 2000 or Windows ME would be the following:

echo @prompt set date=$d$_set time=$t$h$h$h > {a}.bat
%comspec% /e:2048 /c {a}.bat > {b}.bat
for %%v in ({b}.bat del) do call %%v {?}.bat
echo %date% %time% >> log

Another alternative is:

echo. |time |find "current" >> log

For the above batch file to work properly, you must create a file called log by typing edit log and then save and exit the file, creating a 0 bytes file. If this file is not created properly or at all, you will get the error message: Content of destination lost before copy.

Technical support

Reference Questions
MS-DOS Additional questions and answers on MS-DOS.
CH000010 Deleting files in MS-DOS without a prompt.
CH000036 How to execute commands in a batch file in timed intervals.
CH000209 Information about long file names.
CH000319 Creating a blank line in a batch file.
CH000320 How to exit a Windows MS-DOS window through a batch file.
CH000321 How to shut down and restart the computer with a batch file.
CH000322 How to run a batch file each time the computer boots.
CH000323 How to replace the file extensions of several files.
CH000435 How to make a bat executable?
CH000540 How to change the title of an MS-DOS Window.
CH000570 Additional information and options for the rundll32.exe file.
CH000738 Preventing an MS-DOS window from automatically closing in Windows.
CH000754 Deleting files equal to 0 in a batch file.
CH000785 How can I run a batch file at a specific time?
CH000932 How can I run a batch file or other file minimized?
CH000987 How can I make a batch file rename a file to the date or time?
CH001041 How can I play a sound file from a Windows batch file?
CH001049 How can I run a batch file in full screen?
CH001050 How can I loop or start a batch file over after it has completed?
CH001102 Searching for a string of text in an MS-DOS batch file.
CH001313 Hide REM lines from showing in a batch file.
CH001345 How can I start an exe in a batch file?
Forum If your question is not listed on this page, try our online forum.