Beginner’s Guide To Windows Batch Files
Batch programming is one of the easiest forms of programming introduced till yet. Although, many people refuse to consider it as a programming language there are plenty of those who do. If you are interested in making some small applications but don’t want to get your hands dirty, Windows batch files will be a great start for you. Learning some basics about batch files will make your computer experience much easier and interesting. In this tutorial we won’t be covering advanced commands and functions but beginners can learn a lot out of this.
What Is A Windows Batch File?
A batch file is a file which contains a list of several commands which are compiled together to perform those functions as and when needed. Previously one had to type all the commands each and every time they are needed but using batch files you can save the list of commands in a file which you can run at any moment you want to. These functions are performed using a program named “command.com” which comes with our Windows operating system. This file handles some particular kind of functions which MS-DOS used to handle before Windows and most other GUI operating systems were developed.
How To Make A Windows Batch File?
Now, it is time to reveal how to make a batch file. DOS will execute all the commands compiled in a batch file in the order they were entered. All you have to do is choose a text editor, say for example notepad, type all the commands that you want to perform (make sure to enter only one command per line) and save the file with .bat extension. Don’t forget that .bat extension, it is a key point that you should note in your mind.
If everything goes right when you will run this file it will be something like this:
Some Basic Concepts
When you are done editing your Windows batch file, you can place exit command at the end as shown in the first figure, and this will exit the command.com after your functions is performed. Also, you can place pause command in between to give your batch file a break. This will ask user to press any key before continue moving to next command.
When a batch program is executed it shows many other functions that are performed in the background during the execution of a command. You can disable the display of these functions by placing @echo off at the top of your Windows batch file. If at some point, you want to display functions again you can place @echo on.
Some Commonly Used Windows Batch Commands:
Echo: Displays the text written on the screen.
Shutdown –s: Shuts down your computer.
Shutdown –r: Reboots your computer.
Shutdown –l: Logs of your computer.
Pause: Waite for a response from user before moving to next command.
Exit: Exits the application.
Goto: Go to a particular label (a label can be declared anywhere like “lable:”).
Help: Displays help content.
@echo off: Hides background functions.
@echo on: Shows background functions.
Start: Start a particular application, file, or webpage.
Time: Displays the current BIOS time.
Tree: Graphically display the directories and data of a drive or path.
Rename: Renames a file.
Del: Deletes a file.
RD: Removes a directory.
Format: Formats a partition.
There are several other commands one can use, but it would be hard to detail all of them here. You can use help command to get help about more commands.
How to delete folder through batch file