Batch files are scripts that contain a series of commands to be executed by the command-line interpreter of the operating system.
Syntax #
A batch file is a script file with the extension .bat that contains a series of commands to be executed in sequence.
.bat #
The .bat extension is used to identify batch files in Windows.
Batch File Syntax Table #
Syntax | Name | Description | Example |
---|---|---|---|
ECHO | Display | Displays messages on the screen | ECHO Hello, World! |
@echo off | Suppress Echo | Turns off the command echoing feature, making the script output cleaner. | @echo off |
CD | Change Directory | Changes the current directory | CD C:\Users |
DIR | List Directory | Lists files and directories in the current directory | DIR |
PAUSE | Pause | Pauses the batch file execution | PAUSE |
SET | Set Variable | Assigns a value to a script variable. | set VARNAME=value |
:label | Label Declaration | Defines a position in the script that can be jumped to with goto | :start |
GOTO | Jump to Label | Directs the script to jump to a labeled line. | goto start |
if | Conditional Execution | Executes a command if a specified condition is true. | if %VARNAME%==value echo Value is set |
for | Looping | Performs a command or series of commands for each item in a list. | for %%G in (*.txt) do echo %%G |
rem | Comment | Adds a comment or remark to the script, ignored by the command interpreter. | rem This is a comment |
Official Documentations (Learn More) In Depth #
An A-Z Index of Windows CMD commands. -> https://ss64.com/nt/
MICROSOFT Windows Commands -> https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/windows-commands
Batch File Basic -> https://www.geeksforgeeks.org/basics-of-batch-scripting/
Leumas Batch File Boilerplates #
File Name | Actions |
---|