Batch Files – Part 1

For those who are unfamiliar with batch files, I am starting this series to allow you to become better acquainted. A batch files is simply a collection of commands that are executed in a certain order that you specify. Batch files can reference and execute other batch files and can even have argument and variables which make them a great entry level coding experiment. Even if other ways exists to accomplish a task, a batch file can often be the simplest. Batch files are fun to create and always have a level of experimentation and learning about them which make the process fun.

If you have ever used MS-DOS or the “command prompt” of windows, then you shall have no problem with batch file basics. Let us begin with the editor itself. To edit and create a batch file we will use one of two methods. One method is to just open “notepad” and the other is to open a command prompt editing window. Let’s look at the simplest methodology to create our very first batch file.

To start creating a batch file:

  1. Open “notepad”
  2. Type the following:
    @echo off
    echo Hello this is a test batch file that we are creating
    pause
    START /MAX NOTEPAD
    exit
    Batch Example 1
  3. Click “File”
  4. Click “Save As”
  5. In the File Name box, make sure that your name ends in “.bat”, “testing.bat” would work for instance
  6. In the “File Type” drop-down box, confirm that you select “all types” or the similar option

    batch example 2

Now that you have just created your first batch file, let us examine the different parts.

  • @echo off makes sure that only the information we WANT displayed will scroll across the command window
  • echo will read off whatever words are following the command
  • pause forces the user to hit “any key” before the next command will process, this allows time to read our echo
  • START will start-up the specified program. In this case it is notepad. Some programs require the full file path to start
  • I added /max so that the program will start in it’s maximized mode
  • exit will exit out of the command prompt window so that it is not left up unnecessarily

To run this batch file, simply find the saved file and double click. To edit the file again, right click and click “edit” in the pop-up menu.

This is your introduction to batch files. Simple, Fun, and an elegant solution to many issues or needs that a user may have.
We will cover more commands and uses for batch files in the next post of this series. To continue playing around with what we have already learned, try starting OTHER programs such as calculator, firefox, paint and others. Hint: Some files need the FULL file path and some need their “.exe” extension

Until next time!

-Matthew Pizgatti

About Matthew Pizgatti

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Scroll To Top