Pages

Saturday, November 17, 2018

What is a batch files? | uses of a Batch file? | How to make a Batch file ||

A Batch file does the work of a mediator between you and the command prompt. It is a file - with .bat, .cmd,.btm file extensions - containing the CMD commands. When you run a Batch file, the commands written in it are executed in the Command Prompt following a serial fashion. Otherwise, these would have to be entered manually line by line.


What's the use of a Batch file?
Now, why should you keep the commands in a Batch file? A Batch file saves your time. otherwise, would be invested in typing the same commands again and again. For instance, you can schedule your Windows OS to shut down after a specific amount of time using the command prompt. It you have created a Batch file for the shutdown operation. You'll only have to double-click to run it, like you normally open applications, and your Windows will shut down after the time you have already set.

If a developer wants to use the command prompt on your machine while installing software, he can do so by including a Batch file in the setup files. Otherwise, you would have to run the commands which I guess won't make you happy. I a nutshell, it is a script file used to automate tasks in DOS, Windows, and OS/2 operating systems.

While creating a Batch file, you can also enable loop (for), conditional statements (if), control statements (goto), etc. You can run a Batch file directly from the command prompt by typing its name. Also, you can run one Batch file from another Batch file using the CALL commands.

How to make a Batch File
Below are steps on how to make a Batch file on any computer running a Microsoft operating system, e.g. MS-DOS or any version of Windows.

  • Microsoft Windows
  • MS-DOS and Windows command line
Creating a Batch file in Microsoft Windows
In WINDOWS, you can create a Batch file using the steps below or the steps mentioned in the MS-DOS command line section. If you are more comfortable with Microsoft Windows, you can use any text editor (such as Notepad or Wordpad) to create your Batch file; as long as the file extension ends with .bat in the example below, we use the Windows Notepad to create a batch file.
Operating System, e.g. MS-DOS or any version of Windows.

  • Microsoft Windows
  • MS-DOS and Windows command line
Creating a Batch file in Microsoft Windows

In WINDOWS, you can create a Batch file using the steps below or the steps mentioned in the MS-DOS command line section. If you are more comfortable with Microsoft Windows, you can use any text editor (such as Notepad or Wordpad) to create your Batch file; as long as the file extension ends with .bat in the example below, we use the Windows Notepad to create a batch file.

  1. Click Start
  2. Type : Notepad in the Run box and press Enter.
  3. Once Notepad is open, type the following lines or copy and paste them

      4. Click File and then Save, and then navigate to where you want to save the file. For the file name, type "test.bat", and if your version of Windows has a "Save as type" option, choose"All files", otherwise it saves as a text file. Once you have completed these steps, click the Save button and exit Notepad.
      5. To run the Batch file, double-clock it like any other program. Once the Batch file has completed running it closes automatically.