Basics of Batch Script
In the batch script, you mostly write commands that can work in the command prompt. Some are basic commands for printing, pausing, exiting and some commands can be used for different purposes like checking ping, checking network stats and so on. Rather than opening a command prompt each time and typing the command by yourself, you can make the batch script file and just open it to work. There are many commands that you can use in your batch scripts for different purposes, however, some basic commands are listed below:
ECHO – Displays the text on the screen in the command prompt.@ECHO OFF – Hides the display text of command and only shows the message on a clean line.TITLE – Changes the title of the command prompt window.PAUSE – Stops the command prompt window from closing automatically after executing the command.
Note: The name of the file should be different from the default system files, so it does not conflict with each other and create a mess. You can also use the extension ‘.cmd’ the earlier versions of Windows won’t run it.
Writing Simple Batch Scripts
Users can try the simple batch script to understand the commands and working on it. Just like in other programming languages, you print text to understand the printing method; here we will be printing string by using the ECHO command. Follow the below steps to make your first batch script file:
Writing Different Batch Scripts for Different Purposes
Some of the examples to show you the working of batch scripts through different scenarios. Each batch script below will have the same method for making, so we will use the above method for creating the batch script and add any of the below codes instead of the above code.
1. Copying/Moving Files by Using a Batch Script
A batch script for copying files from source to destination. This example can be used for copying or moving photos from your phone or camera SD card to your system folder. This batch file can be used if you mostly use the same source (USB/SD Card) for moving files. Users don’t need to select the new files in the USB each and every time they want to move/copy them on the PC. By defining the source and destination location, you can copy/move files by just clicking this batch script. Note: You can also move files by changing the ‘xcopy‘ to ‘move‘ in the above code.
2. Changing the Files Extension in a Folder
You can also create a batch file for changing the extension of all files in the folder. Extensions can be changed to a similar file format, such as JPG to PNG or it can completely change the working of the file. If the text file has a code for batch script, the user can change the file extension from .txt to .bat as shown below:
3. Checking Ping for Two Different Sites by Using the Single Line Command in Batch Script
This is an example of using the multiple commands for command prompt through a batch script. This depends on the need of the user and their personal preference. There are some useful commands, which can be used one by one to achieve a specific purpose. Down below we have a code for checking the ping of two different URLs: There is much more that users can do with batch scripts by following the batch script rules.
How to use Linux scripts to Tidy up Your Desktop in Windows 10Fix: Execution of scripts is disabled on this systemHow to Fix ‘Running Scripts is Disabled on this System’ Error on Powershell?How to Use AutoHotKey Scripts