How to Create Batch Files in Command Prompt?

Batch files are simply collections of multiple commands in a single file.They are also called script files.They are useful for everyday administrative tasks for which you do not want to remember commands or their syntax.You can create batch files using a text editor such as Notepad; you save batch files with a .bat or .cmd extension. When a batch file is run from the command prompt or called from within another batch file, the commands in the file are executed one by one in the order in which they appear in the batch file. Batch files are very useful in the following situations:

  • When you need to perform similar administrative tasks on a regular basis on a single computer. 
  • When you need to perform a series of administrative tasks on a number of computers 
  • in the network. 
  • When you want to run specific administrative tasks on remote computers and it is 
  • not possible to go to the computer and work on a GUI. 
  • When you want to organize the output of commands run on a computer. 
  • When you need to repeat exactly the same administrative tasks on a number of 
  • computers.

You do not need to be a programmer to create batch files. Batch files are simple collections of commands combined with some operators and parameters. Just open Notepad and write a few simple commands as follows:

Rem * This file is my first batch file *
Echo My First Batch File
Echo Off
Dir
Echo You Just Saw Directory Listing
Echo Bye For Now


When you are done writing these lines, save the file as Mybatch.bat. Open the command prompt, type Mybatch, and press Enter.You will see the output of the batch file displayed in the command shell window.


You might have noticed that all commands used in the batch file are also displayed as they are processed. Every time a command is processed, the command prompt is displayed along with the command itself.To get around this problem, you can use the Echo Off command. This stops commands from being displayed when they are processed.You use the Rem statement in the beginning of the file to insert comments into the file.The text after the Rem command is not processed.You use the Echo command to display a message.

Note: Batch files are considered executable files. You do not need to add the .bat extension from the command line when running batch files. This means that it does not make any difference whether you type Mybatch.bat or Mybatch at the command prompt.

0/Post a reply/Replies

Previous Post Next Post