Batch files in Windows are the script files. A batch file is an unformatted text file. This file consists of a series of commands and has a .bat or .cmd file name extension. The term “batch” is adapted from batch processing – which means non-interactive execution. With batch files in Windows, users can simplify repetitive or routine tasks. When users type the file name at the command prompt, cmd.exe runs the commands sequentially, as they appear in the file. Some typical commands used in the batch files in Windows are – Call, Echo, Endlocal, For, Goto, If, Pause, Rem, Setlocal, and Shift.
How to create .bat or batch files in Windows
As mentioned earlier, a batch file contains a series of DOS commands and are used to automate the frequently performed tasks. Thus, you don’t have to repeatedly write the same commands.
A batch file is created using a Notepad. The text file consists of the commands you want to execute. To create a Batch file, you have to write the command as text in Notepad, and save the file as a .bat file. To execute a command, you simply need to double-click the batch file. Hence, a well-written batch file in Windows can save a lot of time.
Some basic Commands in Batch Files:
- ECHO: To display the text on the screen
- @ECHO OFF: To hide the text
- START: To run a file with its default application
- REM: To enter a comment line in the program
- MKDIR: To create directories
- RMDIR: To remove directories
- DEL: To delete files
- COPY: To copy a file or files
- XCOPY: To copy files with extra options
- FOR/IN/DO: To specify files
- TITLE: To edit the title of the window