Category : Batch File Utilities - mostly for DOS
Archive   : BATTUT.ZIP
Filename : BATTUT.ART

Output of file : BATTUT.ART contained in archive : BATTUT.ZIP
Living with DOS: Intermediate BATch Tutorial
by Barry Simon

Copyright (c) 1986, Capital PC User Group Inc.
This material may be republished only for internal use
by other not-for-profit user groups.

Additional material copyright (c) 1986, Barry Simon

Posted on Compuserve with permission of CPCUG. May not be
reproduced without including the above copyright notice.

Published in the November 1986 issue of the Capital PC Monitor.


One of the tools that most distinguishes the experienced DOS user
from others is the effective use of BATch files. In this article, I
will discuss some of the more advanced features of BATch files and
their commands. I call this tutorial "intermediate" because I have
tried to write in a manner accessible to those with only a little
experience writing BATch files.

Simple BATch files

To begin with, a BATch file is a set of DOS commands which you
place together and which you can issue by just typing the name of
the batch file. The classic example is the batch file which
changes to the directory containing Lotus' 123 and then runs 123.
The same idea can be carried much further; for example, when I execute
my word processor with a batch file, it

o loads the proper set of macros in by keyboard macro program;

o makes a mark using Kokkennen's MARK/RELEASE package;

o loads my thesaurus;

o loads the appropriate mouse menu program;

o runs the words processor; and

o after I am finished with the word processor, clears the macros and
runs RELEASE to boot the thesaurus and mouse menu from memory.

BATch files must be pure ASCII text files with separate commands
on distinct lines separated by carriage return/line feed pairs.
To create your BATch files, you can use EDLIN, a text editor, or any
word processor that produces straight ASCII text files.

BATch programs can contain DOS commands, application program commands,
or a variety of specialized programming features that are known as
BATch commands.

BATch Commands and Features


Your editor may allow you to specify a text file to use as a
parameter on the command line loading it. You would like to
specify the file name as a parameter on the command line calling a
BATch file to start your editor and have this file name passed on
to the editor when it is loaded. This is quite easy. If your
editor is called EDITOR.EXE and you load it via a BATch file
called foo.bat, you need only make the line calling the editor

editor %1

and then call up the BATch file as

foo filename

When the BATch processor comes to the %1, it looks for the first
parameter following "foo" and replaces %1 by that parameter, in
this case by filename.

To be more precise, DOS parses the command line calling the BATch
file into distinct "words" separated by one of four delimiters:

, ; =

That is, it looks for strings of allowed characters separated by
one or more of these special four. Any of the 256 ASCII
characters are allowed in the strings except for these four
delimiters, the three redirection characters (<,>,|) and the ASCII
nul. The first word on the command line is assigned the value %0,
the next %1, etc. Normally, %0 is just the name of the BATch file
but since "." is not a delimiter in parsing the line but is a
delimiter in ending file names, if you have a BATch file foo.bat
and type in


foo.bat will be run and %0 will have the full 17 character string
assigned to it. Similarly, since DOS knows that file names are no
more than 8 characters, the BATch file 12345678.bat will be run if
you type in


but %0 will have an 18 character string. These are admittedly
curiosities but DOS curiosities have a knack of being useful
sometimes. In a real sense, DOS assigns as many parameters as
there are words on the command line, but initially you can only
access the first ten as %0 through %9. Any place that %1 appears
in the BATch file except as %%1, it will be replaced by the first
word after the filename even if that word is the empty word. Any
other time that the symbol % appears in the BATch file DOS will
strip the %-sign away except that %% is replaced by a single
percent and %%1 becomes %1 so if foo.bat has the single line:

echo %%1 has the value %1

then typing

foo junk

will issue the message

%1 has the value junk

There is no limit on the size of any individual parameter other
than the overall limitation that the entire DOS command line can
contain no more than a total of 128 characters.

To summarize, any time %i (for i=0,1,...,9) occurs in the file
except as a %%i, it will be replaced by the ith string in the
command line.

The real limitation of BATch file parameters is that they are not
variables. You cannot manipulate them by parsing them and cannot
change their values.


As a preparation for discussing BATch file GOTO commands, I need
to discuss labels. Any line beginning with the character ":" will
be skipped by the BATch processor when it gets to it. This means
that you can use such lines as remark lines which will not appear
on the screen even if echo is on (in which case lines beginning
with rem do appear). You can also place the redirection
characters <,>,| on such a line (but you cannot place such
characters on a "rem" line). And % signs are not treated
specially on such lines.

While DOS ignores such lines, the string following the : becomes a
label for the GOTO command which I'll discuss next. The first word or
the first eight characters of the first word become the name of that
label. You can also place comments after a label name if you separate
these comments with a space.


The most significant way in which BATch files go beyond the DOS
command line concerns two logical control structures, the GOTO and
the IF commands. The line


  3 Responses to “Category : Batch File Utilities - mostly for DOS
Archive   : BATTUT.ZIP
Filename : BATTUT.ART

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: