Alan Freedman -- The Computer Language Company - Computer Desktop Encyclopedia
Computer Desktop Encyclopedia
Longest-Running Tech Reference on the Planet

A CDE Definition

You'll love The Computer Desktop Encyclopedia (CDE) for Tech Term of the Day (TTOD)



A Windows command that allows a batch file to include multiple tasks and lets the user choose which one to perform. Choice accepts a single character as input. The syntax varies between Windows versions; however, the following three-character example works in Windows Vista, 7 and 8. See batch file abc's.

  @echo off
  choice /c abc
  if errorlevel 3 goto thingc
  if errorlevel 2 goto thingb
  (do thing a here)
  goto end

  (do thing b here)
  goto end

  (do thing c here)

The allowable characters follow the /c, and the example above prompts the user with [A, B, C]?. If any other character is entered, the computer beeps. The input character is stored as an error level: "a" becomes error level 1; "b" is 2 and "c" is 3.

batch file abc's

This tutorial is for Windows PC users who want to routinely perform a series of file management operations without having to enter commands one at a time. Using a text editor such as Notepad, type each command on a separate line in the order of execution. Save the file with a .CMD extension.

If the following commands are saved in a batch file named BACKIMAGES.CMD, every time BACKIMAGES is run, the Xcopy commands will be executed in sequential order:

    xcopy \images\*.gif \backup /m
    xcopy \images\*.jpg \backup /m
    xcopy \images\*.png \backup /m

  C:\BATCHFILES>backimages   run script

Store all batch files in a dedicated folder and add that folder to the Path environment variable so that any batch file can be executed from any prompt (see Path environment variable).

A batch file can include multiple tasks, and the user can choose which one to execute. See Choice.

A batch file can be flexible and accept user input. The percent sign (%) symbol is used to indicate the parameter variables that are replaced with actual user input when the command is executed. Notice the behavior if the following command were in a batch file named SAVE.CMD:

 batch command:  xcopy \%1\*.%2 g:\ /m

 user enters:    C:\>save bob gif

 executes as:    xcopy \bob\*.gif g:\ /m

To stop a batch file in operation, press Ctrl-C or Ctrl-Break.

Quick Reference
The following commands are commonly used in batch files:

  cls        Clear screen
  rem or ::  Remarks
  @echo off  Turn off display
              for this command only
  echo off   Turn off display
  echo on    Turn on display
  echo       Display message; for example,
              echo Press Y for Yes
  call       Call other batch file
  pause      Stop and wait for keystroke

  choice     Input selection (see Choice.)
  if not errorlevel 0 goto :line

  if not exist filename goto :line
  if not string1==string2 goto :line

  %1 - %9   - Input parameter variables

Personal Use Only

Before/After Your Search Term
CHIPRAcholesteric LCD
chips and salsaChooser
chipset graphicschorded keyboard
chirpchording keyboard
chirped pulsechown
CHK filechroma
Chkdskchroma key
chmodchroma sampling
CHMOSchroma subsampling

Terms By Topic
Click any of the following categories for a list of fundamental terms.
Computer Words You Gotta KnowSystem design
Job categoriesUnix/Linux
Interesting stuffPersonal computers
InternetIndustrial Automation/Process Control
Communications & networkingAssociations/Standards organizations
HistoryDesktop publishing
ProgrammingHealthcare IT
System design