Free Software for DOS
Batch Processing – 1
Enhanced DOS Commands

21 Aug 2006

Global Menu:
Go back to Front Page Menus

Go to top of Batch Processing – 2



This page:
IF

SET

ECHO

PAUSE

FOR

DATE

CHOICE

Other page:
UTILITY COLLECTIONS

BATCH COMPILERS

OTHER UTILS

Notes: These pages includes mainly batch utils and other enhanced DOS commands that supplement the DOS batch language. The list does not reflect an exhaustive search. See More Resources - 1 for a list of sites that focus on batch files, tips, and tutorials. Most of the utils below were developed exclusively for DOS and may not operate as expected under Win9x and/or NT. A very big thanks to Howard Schwartz who suggested and commented on many of the programs on this page.
Also see:
REXX / Regina / BREXX – Powerful but comprehensible procedural language, supplement / alternative to DOS batch.
DO – Batch-based file manager.

IF

ERR2ENV — Set current errorlevel to an environment parameter.

unrated

[added 1999-07-07, updated 2004-06-27]

"Dos IF statements need a lot enhancing to test for various conditions: err2env.zip is a life saver that lets you store the current error level in an environment variable and/or set it yourself."

Syntax:
err2env [/qnàx#+#-#[,envpara]] or
err2env "/<>qnàx#+#-#t#[,envpara]" [fileout [filein] ]
         where # represents an positive integer.

q    - quiet with no non-critical messages
n    - environment parameter ERR_LEVEL will not be changed
x#   - exit with errorlevel specified by #
+#   - exit errorlevel will be the entry errorlevel plus #
-#   - exit errorlevel will be the entry errorlevel minus #
à    - remove stored errorlevel addresses from ERR2ENV.EXE
,env - set errorlevel to the environment parameter specified by "env"

Note: May not work properly under Win9x (recursive shell failures).

Author: Zhuhan Jiang, Australia (1994). Suggested by Howard Schwartz.

1994-08-30: v1.0.

Download err2env.zip (18K).


TESTIF — Test for system, disk, time, and file conditions in batch files.

unrated

[added 1999-07-07, updated 2005-04-10]

Tests for: VideoMode, VideoPage, ScreenWidth, Year, Month, Day , DayOfWeek, Hour, Minute , Second , WriteVerify, DosVersion, MinorDosVersion, CurrentDrive, Drives, Floppies, SerialPorts, ParellelPorts, CapsLock, NumLock, ScrollLock, MemSize, Random, SectorsPerCluster(n) BytesPerSector(n), FreeClusters(n), TotalClusters(n), FreeSpace(n), TotalSpace(n) , Exist <FileName> , FileSize <FileName>, FileAttr <FileName>, FileDate <FileName>, Mem(A:B), MemW(A:B), Port(A).

Author: Marc Perkel at Computer Tyme Software Development Laboratory (1990). Suggested by Howard Schwartz.

1990-10-25: v1.2.

Download testif.zip (12K).


TEST — Test for file/directory status in batch files.

unrated

[added 1999-07-07, updated 2005-04-10]

"test evaluates the expression <expression> and, if its value is true, returns a non-zero (true) exit status; otherwise, a zero (false) exit status is returned. test returns a zero if there are no arguments."

Primitive operators testing one file: Primitive operators comparing two files:

The above operators can be combined with logical (AND, OR) operators.

Author: Jason Mathews (1994). Suggested by Howard Schwartz.

1994-04-14 release.

Download test.zip (14K).


Ifnumber — Batch util makes IF-predicatiton bigger/smaller than.

unrated

[added 2001-03-18, updated 2005-04-10]

From the docs:
The normal IF command cannot determine if numbers or numbered variables are big or small, while this one can It is operated by errorlevel code.
Syntax: Ifnumber.exe <number1> <predicate> <number2>
  Predicate can be:
equival, unequival, smallerthan, biggerthan,
smallerequivalthan or biggerequivalthan

If the predicate is true. Ifnumber.exe returns errorlevel 1.
If the predicate is false. Ifnumber.exe returns errorlevel 0.
If the syntax is wrong. Ifnumber.exe returns errorlevel 255.

Author: Frank Dethlefsen, Germany (1999).

1999-11-08: v1.0.

Download ifnumber.zip (6K).


SET

VARSET — Sets variables w/ file-related information; offers integer arithmetic and string operations. Win9x LFN support.

unrated

[added 2001-03-18, updated 2004-04-17]

From the docs:
VARSET sets variables with various file related information, and offers integer arithmetic and string operations. Long file names are supported under Win9x/2000/XP (not under NT).
Syntax: CALL VAR SET varname=expression [options]
Expressions:
        DATE|TIME OF file
        FILES|DIRS OF filespec (wildcards)
        SIZE OF file(s)
        LINES OF file
        VOL OF drive
        DRIVE|-DRIVE OF filespec
        NAME OF filespec
        EXT|-EXT OF filespec
        LFN|SFN OF file or folder
        FULL OF filespec
        STRING(p,l) string
        (arithmetic)
Options:
        /U|L upper|lower case
        /T   thousands separator
        /Rn  right align (total size=n)
        /Zn  fixed length with leading zeros

Author: Horst Schaeffer, Germany (2002).

2002-09-10: v1.1.

Download varset12.zip (9K).

Go to Horst Schaeffer's Software Pages, in Englishauf Deutsch, for more info and other software for DOS & Windows.

More in these pages from Horst Schaeffer.


Advanced Set (Advset, ASET)

unrated

[added 1999-07-07, updated 2005-04-10]

Advanced Set deletes, appends to, prepends to an existing variable, converts values to all caps, all small letters, etc.

Author: Kåre Fundal, Denmark (1995). Suggested by Howard Schwartz.

1995-03-15: v1.4.

Download advset14.zip (12K).


ASET (Advanced SET, ASET/2)

unrated

[added 1999-07-07, updated 2005-04-10]

"ASET lets you store all kinds of information in a variable, and do arithmetic as well (a big lack in batch files)." Can be loaded from the command line or from a file. Large, detailed manual in download packages.

Usage:
   ASET [-ef:hHnprv*] [target {=|:=} expression]

Options (Combined options are not allowed; -e and -f are mutually exclusive):
   -e       Set the ERRORLEVEL according to the result
   -f[file] Read a list of statements from file rather than the command line;
            if file is omitted, standard input is read
   -h       Display this help screen
   -H       Display another help screen with notes and examples
   -n       Do not SET anything (if not -e, -n implies -p)
   -p       Print the result on stdout (default is quiet operation)
   -r       Repeat the assignment on stdout (default is quiet operation)
   -v       Display version info and information about the author
   -*       Display internal information (for debugging purposes)

Author: Richard Breuer, Germany (1993). Suggested by Howard Schwartz.

1993-05-06: v1.0.

Download aset10.zip (80K), or get the program as part of RUTILS4. Note: The EXE in aset10.zip is the smaller one, compressed with Diet.

Online manual (same content as plain text version in download packages).


STRINGS — Enhanced SET.

unrated

[added 1999-07-07, updated 2006-08-21]

"Strings does similar things to ASET, but takes up less memory."

From the docs:
STRINGS enables batch files to manipulate strings, request and interpret user input, process files, return system information, and perform simple math...Stores information in either the local or the master environment...can now act as an extension to the DOS command processor, COMMAND.COM...
Usage: STRINGS [/?][/M][/Q][/Pc][/Bn][/I][/U] [env var =] FUNCTION [Params]

/M  - Use master environment
/Q  - Suppress output to screen
/Pc - Use char c instead of ',' as the parse character
/Bn - Use n as the number base
/I  - Installs as resident code. DOS 3.3 or later required
/U  - Uninstalls if resident
FUNCTION
DESCRIPTION
PARAMETERS
LEFT
Returns left n characters
String, number of characters
RIGHT
Returns right n characters
String, number of characters
MID
Returns middle n characters
String, starting character, length
LENGTH
Returns string length
String
FIND
Finds position of findstring
String, findstring
FINDC
Case-sensitive FIND
String, findstring
LOWER
Returns string all lowercase
String
UPPER
Returns string all uppercase
String
CHAR
Returns ASCII value of character
Character
VAL
Returns ASCII character of number
Number
READ
Returns a line from a file
Filename, line number
WRITE
Writes string to end of file
Filename, string
FILESIZE
Returns file size
Filename
LINESIZE
Returns number of lines
Filename
FILENAME
Returns filename
Filespec
FILEEXIT
Returns file extension
Filespec
TRUENAME
Returns qualified filename
Filename
ASK
Returns user response
[Prompt string]
VER
Returns the DOS version number

ENVFREE
Returns the bytes free in the environment

ENVSIZE
Returns size of the environment

MASTERVAR
Returns a variable from the master environment

ADD
Returns sum of two numbers
Number,number
SUB
Returns difference of two numbers
Number,number
MUL
Returns product of two numbers
Number,number
DIV
Returns quotient of two numbers
Number,number

Extensive online help. Doc files, batch progs and ASM source in package.

Author: Douglas Boling, for PC Magazine (1995). Suggested by Howard Schwartz.

1995-03-27: v2.5.

Download strings.zip (75K).


ECHO

Echo replacements are useful for batch generation and creating logfiles.

Also see QECHO, "quote echo" with control codes, part of the PBATS collection: Somewhat similar to XECHO, below.


LOGECHO — Enhanced ECHO.

[added 1998-03-30]

Roll your own date and time format with this ECHO replacement – best suited to batch files. Using redirection, you can stamp log files with times and dates. You can add text as well, e.g.

LOGECHO Document revised: $D $N, $Y >> project.doc

   $D  day (01..31)........$h  hour
   $M  month (01..12)......$m  minutes
   $N  month (Jan..Dec)....$s  seconds
   $H  month (hex 1..C)....$c  sec/100
   $Y  year (00..99)
   $C  century (19|20)
   $W  day of week (Sun..Sat)
   $V  day of week (0..6)
   $Z  day of year (001..366)
   $$  '$'

Author: Horst Schaeffer, Germany (1997).

2002-08-04: v2.2. Part of the PBATS collection.

Download pbats32.zip in English (60K), or/oder auf Deutsch (64K).

Go to Horst Schaeffer's Software Pages, in Englishauf Deutsch, for more info and other software for DOS & Windows.

More in these pages from Horst Schaeffer.


XECHO — Enhanced ECHO.

* * * *

[added 1999-07-07, updated 2005-04-10]

XECHO is a collection of executable utils and sample batch files, all of them in separate English- and German-language versions. The utils perform various system tests, and the batch files send the results to screen or file.

From the docs:
The echo command often needs enhancement so you can put any ascii character in a file, or echo something to a file without starting a new line. The latter is handy for building commands in a 2nd batch file, created by a first batch file. XECHO is an enhanced echo that does these things and also lets you echo all kinds of information to the screen. XECHO also allows echoing of redirection symbols.

Author: Claus-Jürgen Claussen, Germany (1998). Suggested by Howard Schwartz, others.

1998-03-21: v1.33.

Download xecho133.zip (85K).


SEND — Enhanced ECHO.

unrated

[added 1999-09-12]

From the docs:
SEND is intended to remedy...defects of ECHO:
  1. It does not terminate line in a CR-LF combination; one can add such a pair "by hand".
  2. Typing "send ^G" is equivalent (except for the lack of a CR-LF) to typing "echo <Ctrl G>" so one need not fill files with control characters.
  3. Typing "send ^[E > prn" will send a <Esc>E to the printer thereby turning on "emphasized" print.
  4. In addition...SEND supports the PROMPT $- characters."

Authors: Howard Rumsey and Barry Simon (1985). Suggested by Howard Schwartz. Source, Laurence Soucy's Batfiles: The DOS batch file programming handbook.

1986-01-03: v1.6.

Download send.zip (12K).


Notepad — ECHO substitute, displays user text in pop-up window..

* * * *

[updated 2006-08-21]

Notepad displays text in a window, centered on the screen, then stops like PAUSE, and lets batch operation go on when any key is pressed.

Usage:
1) NOTEPAD {~FnBn} string1 string2 ...
2) NOTEPAD {~FnBn} "string3 string4" ...
3) NOTEPAD {~FnBn} string1 string2 "string3 string4"...

Fn = Foreground color n
Bn = Background color n

In 1), display will be:
    string1
    string2


In 2), display will be:
string3 string4

In 3), display will be:
    string1
    string2
string3 string4

Author: ComPro Software Systems (1995).

1995-06-19 release.

Download notepad.zip (26K).


PAUSE

Also see: Notepad, above, and BEEP.


HoldIt — PAUSE replacement times out after specified time.

* * *

[updated 2005-04-10]

Differs from PAUSE in its ability to timeout after a specified period of time (seconds). HoldIt can also return error level messages. If you use MS-DOS 6+, also look at the CHOICE command which can work in a similar fashion.

Author: Peter Strickler, Switzerland (1993).

1993-05-05: v1.0.

Download holdit10.zip (7K).


PAWS — PAUSE substitute w/ mouse button specific error levels.

unrated

[updated 2006-08-21]

@echo off
rem You could do some work here such as copying files, etc.
rem Then pause the batch, e.g., to check for errors.
echo.
echo Press any key or click with the mouse...
paws
rem (it will be errorlevel 0 on on resume after Ctrl+Break)
if not errorlevel 1 goto continue
if errorlevel 1 if not errorlevel 2 echo Primary Btn clicked!
if errorlevel 2 if not errorlevel 3 echo Secondary Btn clicked!
if errorlevel 3 if not errorlevel 4 echo BOTH Btns clicked!
if errorlevel 4 echo A key was pressed!
:continue

From PC Magazine, 1998-05-05 issue.

1997-12-08 release.

Download paws.zip (1K).

Also see another PAWS, in the Batpower collection.


MPause — PAUSE replacement uses mouse or keys to answer prompt.

* *

From the docs:
If a mouse is detected, then the program waits for any key stroke OR any mouse button press. It prompts you to press any key or mouse button. If no mouse is present, then the action is identical to that of the PAUSE command, including the identical prompt to press any key.

Doesn't add a new line after return. Also see: PAWS, above.

Author: Chuck Somerville (1992).

1992-05-15: v1.0.

Download mpause.zip (3.4K).


PRESS — PAUSE substitute with OK button box, mouse support, time-out option.

* * *

Yet another replacement for the PAUSE command. By default it darkens the screen and displays an OKAY button box. The only problem with this design is that the box can sometimes obscure potentially important screen text. You can add text to the button box, and also use both ok/cancel buttons with errorlevels for decision branching in batch files. Option to time-out after x seconds. Mouse support too.

Author: George Kerber (1995).

1995-02-14 release.

Download press.zip (30K).


FOR

LOCATE — File finder with useful batch creation capability.

LOCATE can function as a user-friendly, functional "analog" of the FOR batch command or the classic SWEEP batch util. Locate can filter a set of desired files using its superior file finding options, and then execute a user command w/ arguments on the set of found files (/C). Alternatively, one can generate a batch file containing a command for each found file (/O). Macros (symbolic representations of directory name, file name, file name without extension, extension only,...see below) can be placed within the user's commands and arguments; these are translated back into their respective specific entities when Locate generates a command for each found file.

The macros are:
   &F  fully qualified filename     C:\WINDOWS\WIN.COM
   &D  directory name, canonical    C:\WINDOWS
   &P  directory name with \        C:\WINDOWS\
   &N  filename                     WIN.COM
   &R  filename without extension   WIN
   &X  extension only               COM
   &S  filespec without drive       \WINDOWS\WIN.COM
   &L  drive letter                 C:
   &A  attributes, standard         +A -S -H -R
   &B  attribute bits               A...
   &W  Win95 full LFN               "C:\Directory Name\Long File Name"
   &Z  Win95 LFN, filename only     "Long File Name"
   &T  terminate line
   &&  ampersand    &E  escape    &Q  quote mark
   &1  date         &2  time      &3  file size

To illustrate a most basic example, LOCATE's /O switch can be used as a wildcard "helper" for programs that don't support wildcards. Suppose you wanted to convert all *.txt files, dated today (switch /D:T), from DOS to UNIX format but your converter program (let's say DOS2UNIX) doesn't have wildcard support. Locate can easily generate a batch file that contains a DOS2UNIX conversion command for each *.txt file it finds:

LOCATE *.txt /D:T /O:"DOS2UNIX < &N > &R.unx" >>CONVERT.BAT

A couple lines from the generated CONVERT.BAT might look like this:
DOS2UNIX < one.txt > one.unx
DOS2UNIX < two.txt > two.unx

For each unique *.txt file found by LOCATE (&N), a new UNIX formatted file will be created with the original file basename (&R) and a new extension defined by the user (e.g., .unx). One advantage of using Locate (e.g., vs. FOR) is the ease with which one can filter for very specific file property combinations (filename, attributes, date, time, etc).

See more about Locate in File Utils - 3.

Author: Charles Dye / Freeware, FreeDOS and 4DOS-related stuff. Suggested by Bjørn Simonsen.

Versions       



2003-12-29:
1.31
"Some features may not work correctly under FreeDOS."
1998-09-30:
1.25d
"This is an older release for FreeDOS compatibility."

Downloads
v1.31
locate.zip
(80K)
v1.25d
loc125.zip
(69K)

Also see: SNiF and FORALL.

More in these pages from Charles Dye.


FORALL — File finder runs commands on found files.

unrated

[added 2000-10-09]

FORALL appears to be functionally similar to LOCATE's /c option (find files and execute user commands on found files). Can function like the classic SWEEP util. FORALL runs under DOS or OS/2; some options are OS/2 specific (+-x).

Usage:   FORALL [options] [pattern] ... : [command] [argument] ...

The following macros will be replaced in the command and arguments:
     @F full file specification     @@ single @
     @D drive identifier and :      @P path name and \
     @S file name and extension     @R relative path name and \
     @N file name               @E file extension
Options: -c      confirm all commands before executing them
     -e[n]   quit if a command returns an exit code >= n
             if -e is specified without n, 1 is assumed
     -n      do not execute commands, only show them
     -u      upper-case expanded file name macros
     -l      lower-case expanded file name macros
     -v      work on files NOT matching the pattern(s)
     -q      quiet mode, do not echo commands to screen
     -f      use / instead of \ as pathname separator in macro expansions
     -R      work recursive through subdirectories

     +r -r   only files with/without READ-ONLY attribute
     +h -h   only files with/without HIDDEN attribute
     +s -s   only files with/without SYSTEM attribute
     +a -a   only files with/without ARCHIVE attribute
     +x -x   only files with/without extended attributes
     -d      only directories
     +t mmddhhmm[yy] -t mmddhhmm[yy]
             only files with a timestamp later/earlier than the argument.
Valid wildcards in patterns:
     ?            match any single character
     *            match zero or more occurrences of anything
     [abc]        match any character of a, b or c
     [^abc]       match any character except a, b and c
     [a-z]        match any character between a and z
     {xx,yy,zz}   match any of 'xx', 'yy', or 'zz'

If using alternatives in {}, when one word is prefix of another one,
order them with the longer word first, i.e {cs,c} instead of {c,cs}.
Example: FORALL -R -r +a D:\WORK\*.{C,ASM,DEF} : COPY @F E:

Author: Kai Uwe Rommel (1995). Suggested by R. Scott.

1995-11-29: v7.2.

Download forall72.zip (30K).


FORTUNE — Enhanced FOR.

unrated

[added 1999-07-07, updated 2002-11-15]

FORTUNE "extends the functionality of the DOS FOR command by providing ways of splitting up the parts of the file name and manipulating the parts." Translate variables into drive, path, filename root, filename extension, and filename characters.

Author: Bruce Guthrie (2002).

2002-08-10: v0208.

Download FORT0208.ZIP (82K).

More in these pages from Bruce Guthrie.


DATE

FDATE (2) — Multi-purpose date manipulation / format utility for batch files.

unrated

[updated 2004-11-09]

Fdate is a powerful utility for performing date formatting and date arithmetic in DOS batch files. Includes a variety of means for placing output into environment variables which can be then be manipulated in numerous ways in a batch file. Detailed and brief help documentation included; multiple help screens.

Features, from the documentation:

Author: Stephen Ferg (2003).

2003-07-04: v16a. Last version – developmemt has ended.

Downloads
Program
fdate16a.zip
(115K)
Docs
fdate16a_html_doc.zip
(248K)

Get more info at the Fdate page.


CHOICE

INPUT — Get console input from within a batch file.

unrated

[added 1999-07-07, updated 2004-06-27]

From a user:
There are a lot of freeware programs that do what DOS CHOICE does, but better – getting input from the keyboard. input.zip is an old one I have used for years. It puts whatever you type in a variable, and also lets you set up the prompt so it takes only y/n answers, converts your input to caps, etc.

Author: William C. Parke (1986). Suggested by Howard Schwartz.

1986-05-07: v.1.0.

Download input.zip (3K).


Go to Top | Front Page ]


©1994-2004, Richard L. Green.
©2004-2006, Short.Stop.