Batch files are the computer handyman’s method for completing things. They can automate everyday tasks, shorten the required time to accomplish something, and translate a complex process into something anyone could operate.
See Also: Windows Batch Script to Take Backup of Server Event Log
Since automation programs like AutoHotKey exist, many people have never written or taken the time to understand bat files, and many don’t even know what they do.
Batch files or scripts are small easy-to-write text files that carry out a series of commands. They can be simple enough that even the average home computer user can take advantage of them.
What is a batch file?
A batch file contains a series of DOS commands, and is generally composed to mechanize regularly performed tasks. Rather than writing the same commands again and again, you can basically double tap the batch file. Composing a batch file is easier than it looks; the troublesome part is ensuring that everything happens organized appropriately. Well-made batch files can save you a lot of time over the long run, particularly on the off chance that you deal in repetitive tasks.
These are simple text files containing some lines with commands that get executed in sequence, one after the other. These files have the unique extension BAT. Files of this type are perceived and executed through an interface (infrequently called a shell) gave by a system file called the command interpreter. In Windows XP/Vista the command interpreter is the file cmd.exe.
In this article, I’m going to show you how to write a simple batch file and present some basics that a user will need to understand when writing one.
Step to creating a batch file in Microsoft Windows
You can use any text editor (such as Notepad or WordPad) to create your batch files, as long as the file extension ends with .bat. You can create a batch file using the steps below:
1) Open Notepad: Notepad provided with operating systems and software development packages, and can be used to change configuration files, documentation files and programming language source code. You can open Notepad by clicking Start → Programs → Accessories → Notepad. Also you can open notepad through Run box. Just write notepad in the Run box to open it.
2) Write a Program: One of the easiest ways to learn how to create batch files is to focus on doing basic tasks first, type the following lines or copy and paste them. In this program we will list all the files in Intel directory using bat script.
echo We are going to list all files in Intel Directory using bat
Click on Save As..
Click the “Save as type” dropdown menu.
Select “All files” and enter a name for the program followed by .bat or .cmd.
Make sure the encoding is ANSI and save the file.
3) Run the Batch File To run the batch file, double-click on it. Once the batch file has completed running it closes automatically.
Some Basic Batch Commands: Batch files run a series of DOS commands, so the commands that you can use are similar to DOS commands. Some of the more important ones include: ECHO: Displays text on the screen @ECHO OFF: Hides the text that is normally output START: Run a file with it’s default application REM: Inserts a comment line in the program MKDIR/RMDIR: Create and remove directories DEL: Deletes a file or files COPY: Copy a file or files XCOPY: Allows you to copy files with extra options FOR/IN/DO: This command lets you specify files. TITLE: Edit the title of the window.