A batch file is a type of script file used in Microsoft Windows, consisting of lines with commands stored in a plain text file with the extension “.bat” or “.cmd”, which are sequentially executed by the command-line interpreter. Batch scripting increases productivity because it is a way of automating daily IT tasks such as deleting files, starting tasks or capturing information.
To create a Batch file no compilers are required, a simple notepad application is enough. The basic Notepad available in any version of Windows will do.
Open Notepad.
Let’s create the standard “Hello World”.
The script is below. Keep in mind that the commands are case insensitive.
A quick overview of the commands:
- REM – Used for comments that will not be printed to console or executed
- TITLE – Sets the execution window name
- ECHO – Prints text to the console
- PAUSE – Stops the execution until a key is pressed
- EXIT – Exits the script and closes the execution window
- @ECHO – Defines if the commands are hidden or displayed during the execution
The file need to be saved with a “.bat” or “.cmd” extension. In this case “File“, then “Save As…“
Then select the location, change the “Save as type:” to “All files (*.*)“
Type the desired file name and ensure that the extension is “.bat”.
The file will look like this in the directory.
The result of the execution is as below.