Dec 282017
Unix util. for DOS, clean temp. dirs.
File CLNTMP.ZIP from The Programmer’s Corner in
Category File Managers
Unix util. for DOS, clean temp. dirs.
File Name File Size Zip Size Zip Type
CLNTMP.DOC 8892 3124 deflated
CLNTMP.EXE 27350 14112 deflated
CLNTMP.MOD 29367 7482 deflated

Download File CLNTMP.ZIP Here

Contents of the CLNTMP.DOC file

CLNTMP.DOC - documentation for program CLNTMP.EXE

The files present in CLNTMP.ARC should include:
CLNTMP.DOC - this file
CLNTMP.EXE - executable version of program
CLNTMP.MOD - Modula-2 source code to program

The program CLNTMP was written by Randy Maddox using the Logitech
Modula-2 version 3.03 compiler system. If you are programming
in Modula-2, I reccommend this system very highly. If you are
not programming in Modula-2, I reccommend that you start doing


The easiest way to use CLNTMP is to include it in your AUTOEXEC.BAT
file so that your ..\TMP directories are automatically cleaned
every time you boot up. My hard disk is partitioned into two
logical drives, C: and D:, so my AUTOEXEC.BAT file includes the

C: {set default drive to C:}
clntmp /15 {get rid of C:..\TMP files older than 15 days}
D: {set default drive to D:}
clntmp /15 {get rid of D:..\TMP files older than 15 days}

You can, of course, just invoke CLNTMP at the command line just
as with any other program to clean your ..\TMP directories only
when you specifically desire.

The CLNTMP program emulates a convenient function of the Unix
operating system under MS/PCDOS. Under Unix you can set up
directories whose path ends in /tmp to be used as temporary
storage areas. Upon system boot-up Unix will find all of those
../tmp directories and delete any files found there. It is
possible to specify a time as a number of days so that only
files older than the specified number of days are deleted.
CLNTMP provides this same convenience under MS/PCDOS. The
executable version provided in this file will run without
modification on any PC, XT or AT compatible computer using
MS/PCDOS 2.0 or higher. If you try to run CLNTMP without
the proper command line argument you will get the following

calling format is:

clntmp /n

where: MinN <= n <= MaxN

Action: Clean directories ...\TMP of files older than n days.
Only affects current default drive when clntmp is called.
Will find all directories that end in \TMP on current drive.
Gives names of directories found and number of files deleted.
Will NOT find subdirectories with any special attributes set.
Will NOT delete files with any special attributes set.
Assumes current system date is correct.
CTRL-X terminates program operation.
Requires MSDOS 2.0 or better.

The constants MinN and MaxN are defined in the program text and
are currently set to MinN = 0 and MaxN = 65355. As described
above, CLNTMP will start searching from the root directory on
the current default drive and find any directories whose path
ends in \TMP and will then delete any files in those directories
that are older than n days. Any errors in processing or in the
command line will result in appropriate error messages along
with a repeat of the above instructions.

Note that the program will not search any directories with special
attributes set, nor will it delete any files with any special
attributes set. This means that any directory or file that is
set to hidden, read-only, or system will not be affected by the
program. In addition, since such special attribute directories
are not searched at all, any subdirectory of a special attribute
directory will not be found by the program. This allows the user
to protect any file or directory from the program. See the DOS
command ATTRIB in your manual, or use the Norton Utilities to
set/reset these special attributes.

Also note that the program assumes that the current system date
is correct. The program uses the system date to determine the
date n days ago in order to decide which files to delete. If
the system date on your computer is not correct, then files
will have the wrong file creation date and CLNTMP will also
calculate an incorrect file deletion date. See the DOS DATE
command in your manual to set the correct date.

The program cannot be aborted using CTRL-C or CTRL-BREAK as
these might interrupt the program at an inconvenient point.
Instead use CTRL-X to abort the program safely.

Typical screen output from CLNTMP appears as follows:

CLNTMP - temporary directory cleaning program, Version 3.0, 5/23/88
Written in Logitech Modula-2, by Randy Maddox, for BDS, Inc. (703) 481-8700

CTRL-X terminates program at any point.

Total subdirectories = 25 ..\TMP subdirectories = 1

Deleting ..\TMP files created prior to (mm/dd/yyyy): 2/1/1988

Cleaning: \TMP

Files deleted = 5

The screen output from CLNTMP is completely redirectable using
the DOS redirection operator, e.g.,

clntmp /15 > tmp.txt This would find all ..\TMP directories
and delete any files there older than
15 days. The screen output shown above
would appear in the file tmp.txt

clntmp /15 > nul As above, except that the screen
output would be written to the DOS
nul device, i.e., just discarded.

If the second example above occurred in a batch file (.BAT),
then any error messages that might occur would also be sent
to the DOS nul device. However, it would still be possible
to detect whether an error had occurred by using the batch
processing command:


since CLNTMP always sets the DOS ERRORCODE upon termination.
The errors and corresponding ERRORLEVEL and error messages
that may be returned by CLNTMP are:

0 Normal termination, no error
1 Delete failed on:
2 CTRL-X, program terminating at user request
3 Command line option not present
4 / not found in command line
5 No digits following /
6 Unable to convert digits to CARDINAL number
7 n parameter out of range
8 Incorrect DOS version, requires 2.0 or higher
9 Got lost in directory tree, please call Randy
? Please call Randy, unidentified error number:

ERRORLEVEL 1 is a non-fatal error, but may indicate some problem
with your disk or with the file. ERRORLEVEL 2 is fatal, but
normal since it is the user abort. ERRORLEVEL 3 or above is
fatal and results in program termination with no files deleted.
Thus you would use:


in order to detect only fatal, not normal, program terminations.


The Modula-2 source code in CLNTMP.MOD is intended for your use
and exemplification. It uses a dynamically allocated tree
structure to keep track of the directories found and a singly
linked list for the ..\TMP directories. It interfaces quite
intimately with the operating system and you may find some
useful tricks there. In particular, note the constants LAHF
and FlagMask used to detect errors returned by DOS. CLNTMP
only detects that an error has occurred, but you could also
then mask off AL to get the error code and get further error
information via the extended error information function.
If you plan to deal with the operating system at this level,
you should have handy your "DOS Technical Reference Manual"
or, probably even more helpful to most people, Ray Duncan's
wonderful book "Advanced MSDOS".

If you find any errors in the source, I would appreciate
notification and a copy of your correction. If you pass the
source along to others, I only request that you do not remove
my name from the program header.

Thanks, and happy programming.

Randy Maddox

 December 28, 2017  Add comments

Leave a Reply