Batch file

Filename extension .bat, .cmd, .btm
Type Scripting
Opens with Windows Shell
any text editor
File formats category - v  e   edit

A batch file is a text file containing lines of commands to be executed by the command-line interpreter.



Batch files also implement syntax common to programming.

if: conditional statement

  • if String1 == String2 Command - tests if the strings are equal, and executes the command
  • if errorlevel Number Command - tests if a previous command executed returned an exit code greater than or equal to that the specified number.
  • if exist Filename - tests if the file with the specified filename exists.

A not can be used after the if to check instead if the condition is false. An else can be attached to the end to indicate a command to be executed if the first condition was not performed (that is, if the condition is false, or, when not is used, true).