Command Prompt for Windows




Batch Files

What is a Batch File?

A batch file is a simple text file that contains a sequence of programs or commands to run. In order to distinguish a batch file from a ordinary text file, batch files have a file name extension of either .BAT, .CMD or .WBT. Any text editor (eg. NOTEPAD.EXE ) can be used to create and write a batch file. The batch file can be saved as either an ANSI text file or a Unicode text file (ie. UTF-8, UTF-16 LE or UTF-16 BE). Use which ever file format is more appropriate for your batch file.

When a batch files is run from the command prompt, the batch file will be displayed inside the main WinOne® Command Prompt window, unless the CALL command is used to run the batch file, then the batch file will be displayed in a separate window or if an appropriate PIF file exists then it may be run full screen. For more information on PIF files see the help file for the program PIFEDIT. Additionally, .BAT and .CMD batch files can be started from Explorers' Context Menus, by right clicking on the icon (to display the Context Menu) and selecting the appropriate option. .WBT batch files are a special case and can be run from Explorer by simply doubling clicking on the icon for the batch file. .WBT batch files should be used for batch files that are unique to the WinOne® Command Prompt and that will not run with CMD.EXE or COMMAND.COM, such as batch files that include Dialog Box ' s.

When a batch file is run so that it is displayed in the main WinOne® Command Prompt window, then the complete batch file is loaded into memory before the execution of the commands in the batch file starts. This greatly improves the performance and speed of batch files.

There are a number of batch commands that can be used in a batch file to enhance the capabilities of batch files. The batch commands, listed below, are separated into three categories, standard, enhanced and dialog batch commands. Standard batch commands are compatible with CMD.EXE. Enhanced and Dialog batch commands are native to the WinOne® Command Prompt and therefore they are not supported by CMD.EXE. Typically, when a batch file is destined to run under different command shells then the enhanced and dialog batch commands should not be used. When this requirement is not necessary then the use of enhanced and dialog batch commands will greatly improve the functionality and usefulness of batch files.

Standard Batch Commands
  • CALL
  • Run a second batch file, then return to the first batch file.
  • ECHO
  • Display a message or turns echo on or off.
  • ENDLOCAL
  • End the localisation of environment variables.
  • FOR
  • Perform a command for each file in the specified set of files or perform a command a given number of times.
  • GOTO
  • Switch to another part of the batch file, and continue executing the program from that point.
  • IF
  • Perform conditional processing in a batch file.
  • PAUSE
  • Suspend processing of a batch file and display a message.
  • REM
  • Allows comments inside a batch file.
  • SET
  • Display, set or remove environment variables.
  • SETLOCAL
  • Set the localisation of environment variables.
  • SHIFT
  • Change the position of replaceable parameters in a batch file.

    Enhanced Batch Commands
  • ASK
  • Ask a yes/no question and set the errorlevel respectively.
  • BEEP
  • Send a beep to the system speaker.
  • BOX
  • Display a box in one of four pre-defined formats.
  • CALC
  • Perform basic arithmetic calculations in a batch file.
  • CALLPROC
  • Call a procedure with in a Batch file.
  • CHARNEXT
  • Determine the number of code-points in the first character of a string.
  • CHARPREV
  • Determine the number of code-points in the last character of a string.
  • COLOUR
  • Change foreground and background screen colours.
  • COG
  • Get a value from a COM object property.
  • COM
  • Call a COM object method.
  • COMMA
  • Insert commas into a number.
  • COP
  • Put a value into a COM object property.
  • DATA
  • Clear or add items to a global list
  • DATE2SER
  • Convert a date to a serial date value.
  • DIRS
  • Display the directory stack.
  • DISKFREE
  • Determine the amount of free disk space for a disk drive.
  • DISKUSED
  • Determine the amount of used disk space for a disk drive.
  • DO
  • Conditionally perform a command one or more times.
  • END
  • End a batch file.
  • ENUMREG
  • Enumerate all the keys in the System Registry for the specified hkey.
  • FILEDATE
  • Get the last modified date of a file.
  • FILESIZE
  • Get the size in bytes of a file.
  • FILETIME
  • Get the last modified time of a file.
  • FILETYPE
  • Determine whether a file contains text or binary data.
  • GETINI
  • Get an initialisation file key value or enumerate all the key names in a section.
  • GETKEY
  • Wait for a single keypress from the user.
  • GETNUM
  • Wait for a sequence of keypresses from the user.
  • GETSTR
  • Wait for a sequence of keypresses from the user.
  • GETREG
  • Get a System Registry value or enumerate all the names for the specified hkey. The value is stored in an environment variable.
  • GOSUB
  • Jump to another part of a batch file, and continue executing from that point until RETURN is countered.
  • LET
  • Evaluate an expression and set the specified environment variable with the result.
  • LOCATE
  • Position the cursor anywhere on the screen.
  • LOWER
  • Convert a text string to lower case.
  • PARSE
  • Allows a sentence to be broken into pieces.
  • PLAY
  • Play a wave sound file.
  • POPD
  • Pop a directory from the directory stack and make this directory the current directory.
  • PUSHD
  • Push the current directory onto the directory stack and change to the specified directory.
  • READ
  • Read the next item from the global list.
  • READLN
  • Read a line of text from a file.
  • RETURN
  • Return execution to the next command following the GOSUB command.
  • SAY
  • Display a message. This command with not add a carriage return - line feed at the end of the message.
  • SEED
  • Randomise the random number generator or set the seed to a specified value.
  • SER2DATE
  • Convert a serial date value to a date.
  • SETINI
  • Set or delete an initialisation file key value.
  • SETREG
  • Set or delete a System Registry value.
  • SLEEP
  • Do nothing for a time.
  • STOP
  • Stop processing a batch file and continue processing the batch file that called this one.
  • STRFIND
  • Find the first occurrence of a string within the specified text.
  • STRFOLD
  • Normalize or fold a Unicode string as specified.
  • STRPAD
  • Pad a text string with space characters.
  • STRREP
  • Replace all occurrences of a string within the specified text with another string.
  • STRREV
  • Reverse all the characters in a text string.
  • STRRFIND
  • Find the last occurrence of a string within the specified text.
  • STRSIZE
  • Determine the length of a string.
  • STRSPLIT
  • Split a string at the specified position.
  • STRTRIM
  • Remove leading and trailing space characters from a text string.
  • SUBSTR
  • Extract a section of text from a text string.
  • UNTIL
  • Conditionally perform a command zero or more times.
  • UPPER
  • Convert a text string to upper case.
  • WHILE
  • Conditionally perform a command zero or more times.

    Dialog Batch Commands
  • CBADD
  • Add a string or return the number of strings contained in the list box of a combo box.
  • CBDELETE
  • Delete a string from the list box of a combo box or clear the contents of a combo box.
  • CBDIR
  • Add a list of file names to the list box of a combo box.
  • CBFIND
  • Search the list box of a combo box for a string.
  • CBGET
  • Get the index of the currently selected string in the list box of a combo box.
  • CBINSERT
  • Insert a string into the list box of a combo box.
  • CBSET
  • Set the current selection for the list box of a combo box.
  • CBTEXT
  • Get a string from the list box of a combo box.
  • CHECK
  • Set the state of a check box.
  • DLGBOX
  • Create a dialog box.
  • DLGEND
  • End a dialog box.
  • DLGENDALL
  • End all dialog boxes.
  • DLGITEM
  • Add an item to a dialog box.
  • DLGMENU
  • Add an item to a dialog boxes menu bar.
  • DLGSHOW
  • Display a dialog box
  • ENABLE
  • Enable or disable an item in a dialog box.
  • GETFOCUS
  • Retrieve the identifier of the dialog item that has the keyboard input focus.
  • GETTEXT
  • Retrieve the caption of a dialog box or the text of a dialog box item.
  • GREY
  • Grey or ungrey a menu item in a dialog box.
  • ISCHECKED
  • Determine the state of a check box or a radio button.
  • ISENABLED
  • Determine whether an item is enabled or disabled.
  • ISGREYED
  • Determine whether or not a menu item is greyed.
  • ISTICKED
  • Determine whether or not a menu item is ticked.
  • LBADD
  • Add a string or return the number of strings contained in a list box.
  • LBDELETE
  • Delete a string from a list box or clear the contents of a list box.
  • LBDIR
  • Add a list of file names to a list box.
  • LBFIND
  • Search a list box for a string.
  • LBGET
  • Get the index of the currently selected string in a list box.
  • LBINSERT
  • Insert a string into a list box.
  • LBSET
  • Set the current selection for a list box.
  • LBTEXT
  • Get a string from a list box.
  • RADIO
  • Set the state of a group of radio buttons.
  • SETFOCUS
  • Set the keyboard input focus to the specified dialog box or item.
  • SETTEXT
  • Set the caption of a dialog box or the text for a dialog box item.
  • TICK
  • Tick or untick a menu item in a dialog box.