home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1999 January
/
Chip_1999-01_cd.bin
/
zkuste
/
delphi
/
D1
/
UDIR11.ZIP
/
UDIR.DOC
< prev
next >
Wrap
Text File
|
1995-09-29
|
17KB
|
403 lines
┌───────────────────────────────────┐
│ THE ULTIMATE DIRECTORY LISTER │
│ from │
│ The FastAid Co. │
│ (c), 1990 │
└───────────────────────────────────┘
The Ultimate Directory Lister lets you ...
--list any, or all, files in a specified directory and its
subdirectories.
--stop the listing after the specified directory
--redirect the output to a file or printer
--sort the directory by name, date, size and attribute
--perform a crude but effective "whereis" operation
--find all new files on a disk
--format the output in one of several ways
--perform a pseudo batch operation using an @file
--pause the listing to prevent scrolling
--find the subtotals and grand total of all files chosen
--use wild card searches and search for hidden, system,
read-only files, and directories.
Here's how...
IF YOU Type UDIR, at the DOS prompt,...
YOU WILL GET A listing of just the fully qualified names of all
the files in the current directory AND the fully
qualified names of all the files in the subdirectories.
You can get the same result if you type UDIR . (UDIR
followed by a space and a period)
IF YOU Type UDIR .. at the DOS prompt,...
YOU WILL GET A list of the FQ filenames (i.e. the file name preceded
by the drive letter and the path) for the parent direc-
tory of the current directory and all the subdirectories
attached to the parent.
IF YOU Type UDIR \ at the DOS prompt,...
YOU WILL GET A list of all the FQ filenames for the root directory
and all the subdirectories on a disk. (This is sort of
like the result of using CHKDSK /V.)
IF YOU Type UDIR \*.DOC at the DOS prompt,...
YOU WILL GET A list of all the files that end in ".DOC" beginning
in the root directory and continuing for all subdirec-
tories. You could also use \ad*.doc as a way to find all
files that begin with "ad" and end with ".DOC" on the
disk. Think of this as a substitute for the typical
"whereis" program.
IF YOU Type UDIR C:\UTIL at the DOS prompt,...
YOU WILL GET A list of all the files in a directory named \UTIL on
the C:\ drive along with the files in any subdirectories
attached to C:\UTIL.
IF YOU Type UDIR A: at the DOS prompt,...
YOU WILL GET A list of all the files on the disk in the A: drive.
IF YOU Type UDIR ! at the DOS prompt, where "!" may precede
or succeed any other parameter such as "\" or "A:\",...
YOU WILL GET A listing of the files in only the directory specified:
no subdirectories will be accessed.
IF YOU Type UDIR @filename at the DOS prompt and, if you have
prepared a file with the title "filename" , (more of
that later)....
YOU WILL GET As many listings of files as have been called for in
the file with the @filename.
SUMMARY SO FAR
The FIRST parameter that follows the UDIR command may contain
1) the drive letter and ":" for any existing drive,
2) the name of any directory that exists on the specified drive
3) the name of a file to search for, or any group of files as
specified by the wildcards "*" or "?"
4) the exclamation point "!" to stop the listing after the specified
directory.
5) the "@FileName" parameter which will designate a text file with any
name. The text file may contain any number of lines of valid
command-line parameters for the UDIR program. Examples will follow
after showing what else you can do with UDIR.
AND NOW FOR THE SECOND, AND SUBSEQUENT, COMMAND LINE PARAMETERS...
The second and subsequent command line parameters begin with either the
symbol "/" or "-" . There are many different options from which you may
choose.
1) File attribute options : Archive, System, Hidden, Read-only, Directory
You may call for any, or several of these options by adding the
command line switch(es) in the form /A /S /H /R /D. You may also
group the switches together as in /AHD.
If you choose to invoke each switch with a preceding / or - sign,
then there must be a space between the switches.
These switches act as filters for the final output. For example, the
switch /AR will show only those files whose Archive bit and/or Read-
only bit is set. Similarly the /D switch will show only the direc-
tories on the disk. This may appear to be something like a "tree"
command, but it is different. For instance, if you give the command
UDIR \ /D , you will get a listing of all the subdirectories in the
root directory followed by all of the directories in each of the
subdirectories contained in the root directory. UDIR considers
subdirectories to be the same as files, which, indeed, they are.
The default, when no filter is used, is to show all filenames
including the names of subdirectories.
If you wish to exclude the names of subdirectories from the
listing, use the switch /AHRS.
2) Sorting options : name, extension, size, time, attribute
You may call for any ONE of these options by specifying /n /e /s /t /a.
Note that the sorting switches are in lower case whereas the
attribute switches are in upper case.
You may also add this option to the single parameter for the attri-
butes. For example, UDIR /ARs would produce a listing of all
files in the current and child subdirectories whose Archive and/or
Read-only bit are set. The list will be sorted by size.
NOTE that the sorting is done for each directory rather than a
global sort.
The directories are always presented in alphabetical order.
3) Pause option : p or P
You may use this option by specifying /p or /P or you may add it to
the list of other switches. It will stop the listing and say
---MORE--- at the bottom of the screen. Press any key to continue
the listing or press Ctrl-C to stop the listing.
(NOTE: if you have called for a listing of files on a different
disk, and abend the listing before it's complete, you may wind up
with an A:\ prompt rather than a C:\ prompt. )
4) The total option: T (Use only upper-case to avoid conflict with the
"t" option which is the option to sort by time.)
The /T switch produces a file-count and a byte-sum for the files
shown in each directory along with a grand total of the number of
files and the total byte count at the end of the listing. The final
sum is shown in Kbytes.
The switch may be added to the ever growing list of switches. For
example UDIR \ /ARsTp
5) Formatting options: 1 2 3 4 5 6 7
/1 is the default display format. It produces a list of only fully
qualified names. This would be a good choice to use to produce a
list of all new files on the disk. For instance \ /A1pn (or /APn)
would give a list of all files whose Archive bit is set. The list
would pause to prevent overflowing the screen. It would also be
sorted by name.
/2 gives a list of fully qualified filenames preceded by "%1 " and
followed by " %2". This listing could become the basis for a batch
file. For example if you used the command ! /A2 > newfls.bat, you
would create a file called "newfls.bat" which would contain lines
such as
%1 C:\TP5\TPC\LINKLST.PAS %2
%1 C:\TP5\TPC\WIN.TPU %2
%1 C:\TP5\TPC\ADIR.PAS %2
%1 C:\TP5\TPC\UDIR.DOC %2
You could then run the batch file : NEWFLS COPY A:\TP5\TPC
"COPY" would replace %1 and "A:\TP5\TPC" would replace %2 on each
line. Then you could use NEWFLS DEL to erase all the new files.
Or you could use UDIR !*.pas /A2 > vufls.bat and then use the command
VUFLS TYPE
This would let you view each of the ".PAS" files whose Archive bit
is set in just the current directory.
/3 produces a list of fully qualified filename along with their
size (actual number of bytes). It is most useful when combined with
the /A and /T switches. For instance UDIR \ /ATp3s would give a
paused list of all files on the disk whose Archive bit is set. The
list would be sorted by size, in each directory, and the sizes of
the files would be shown along with subtotals and grand total.
This would be a good option to use when you want to create a
commented list of files. Just use UDIR /3 > filex . Then you can
use a text editor to append descriptions of the files to the
listings.
/4 yields a listing that may be useful in approximating how many
files from a hard disk would fit on a partially filled floppy disk.
The listing shows the fully qualified filename, the size, in bytes.
Then the number of clusters used on the disk are shown, along with
the cluster size. Finally the product of the number of clusters and
cluster size is displayed followed by the "slack" bytes (the number
of bytes wasted due to the way that DOS puts files on the disk.)
Different types of disks have different cluster sizes. 360K and
720K disks have cluster sizes of 1024 bytes. 1.2M and 1.44M disks
have cluster sizes of 512 bytes. Some hard disks have clusters of
either 1024, 2048, or even 4096 bytes.
I have not been able to find a suitable function call that will
determine the cluster size of all disks. Thus I have made the
cluster size a choice for the user.
You may specify which cluster size you wish to use by using the
command line switches, "W","X","Y","Z". These may be used to
pick a cluster size of either 512, 1024, 2048, or 4096,
respectively. The default cluster size is 1024.
I leave it to the interested user to figure out how this
information might be used to determine the amount of space needed
on one disk to accommodate files from another disk.
/5 creates a list showing the FQ filenames along with sizes and
the age of the files in days. If the file was created on the
day you produce the list, then "TODAY'S DATE" label will
appear. If you are running on a computer which does not have a
built in clock and you forgot to set the time and date, you may
get labels showing "FUTURE DATE" or some exorbitant number of
days.
Try UDIR \ /t4p or UDIR \! /Dtp4 (This is the only way to sort
the directory names. It will also show which of your
subdirectories have been around the longest.
/6 produces a listing somewhat like a typical directory listing. It
shows the fully qualified filename, size, date, time and attribute
bits set for each of the files specified.
/7 produces a listing just of directories and subdirectories, with
the number of files and total bytes of each.
6) /? gives you the help screen, which, incidentally, appears
whenever you enter an invalid command line parameter.
USING AN @FILE
Suppose you wanted to use UDIR several times in succession. Each time
you wanted to use a different set of command line switches.
Of course, you could write a batch file that would accomplish this.
However, there is an easier way.
Just use an ASCII text editor (or the COPY CON command) to create a
file that is made up of separate lines, each of which would be a look-
alike for a set of switches.
For example, here is a file, called PARMFILE
\! /D
*.pas /ATt4
\c /RAT5s
The first line creates a list of the subdirectories contained in the
root directory.
The second line lists only the .PAS file in the current and child
directories whose Archive bit is set. The list is sorted by time and
is shown in format /4.
The third line would show the files in the \C subdirectory whose
Archive Or Read-only attributes are set. The list would be sorted by
size and shown in format /5 with totals.
Once you have created the file, you may use it as the ONLY command
line parameter for UDIR. The command, in this instance, would be
UDIR @PARMFILE
I/O REDIRECTION
Since UDIR does not use any fast screen writing techniques, the
lists may be sent to a disk file or the printer using the ordinary DOS
I/O redirection commands: <, >, |
The only caution is that I/O redirection will not work in an @file.
You can use UDIR \! /D > DIRS at the DOS prompt. You can't use the
same command in PARMFILE. However, you could use the above PARMFILE
and the command UDIR @PARMFILE > LISTS to send all of the output, for
each of the three lines, to a file called LISTS. In the file each list
will be separated by a blank line.
TECHNICAL STUFF
The UDIR program does much of what a directory lister could do.
I wrote the program to satisfy my own curiosity about how the
findfirst() and findnext() routines really work in Turbo Pascal and
Turbo C. I also got tired of using several different directory listing
programs to get the information I wanted.
WHAT information? Well, which files, on my hard disk, are new. What
are the ages of files and directories on a disk. What are the sizes
of the files in bytes and in clusters?
I wrote a program to solve all the above problems. THEN I got carried
away and wrote a program that may very well be a solution in search of
a problem.
The algorithm used in the program is shown in the following diagram.
╓───────────╖
║ DIRECTORY ║
║ LISTER ║
╙─────╥─────╜
╓────────────╥───────────╨───╥──────────────────╖
║ ║ ║ ║
╓────╨─────╖ ╓────╨──────╖ ╓──────╨──────╖ ╓─────────╨─────────╖
║INITIALIZE║ ║BUILD A ║ ║GET DIRECTORY║ ║FOR EACH DIRECTORY ║
║VARIABLES ║ ║LINKED ║ ║NAMES FROM ║ ║1. ACCUMULATE ║
╙──────────╜ ║LIST OF ║ ║LINKED LIST ║ ║ FULLY QUAL'D ║
║DIRECTORIES║ ║ ║ ║ NAMES ║
╙───────────╜ ╙─────────────╜ ║2. SORT,IF DESIRED ║
║3. FILTER USING A ║
║ MASK,IF DESIRED ║
║4. PRINT, USING ║
║ CHOSEN FORMAT ║
╙───────────────────╜
The liberally commented source code is included for your perusal and
learning.
The code is written with only a couple of instances of nested
procedures. This might facilitate translating the program to C code.
The only "tricky" part is in the use of the line
readln(inf,string(ptr(prefixseg,$80)^));
in the "input_from_file" procedure. This line reads a line from an
external file and jams it into the command line buffer. This lets me
use the paramstr() procedure, in Pascal, to do any parsing of the
command line. If you translate this program to C, you might want to
use the strtok() function. I have Neil Rubenking to thank for the
trick with prefixseg.
DISCLAIMERS
The UDIR.EXE, UDIR.PAS and UDIR.DOC files are copyrighted by the
FastAid Co. However, they are, hereby placed in the public domain.
There is no charge for their use or distribution. There is no support
for any problems encountered (but to the best of my knowledge there
are no glaring bugs.)
The copyright implies that, if you distribute the code, executable, or
documentation file, in whole or in major part, you leave the copyright
notice attached. If you use parts of the code in your own program,
then it becomes your code. You copyright it if you want to.
The UDIR files are submitted "as is" with no guarantee that they will
do exactly what you want them to do. To the best of my knowledge, the
program will cause no harm to any MS-DOS computer on which it is run.
However, since the source code is made available, I can't accept
responsibility for what might happen if you modify and recompile the
program and then run it.
UPDATE NOTES
The 1995 update of this useful program and source code were to (1) fix
a memory problem in the original that would cause a heap overflow if a
gigantic number of files were listed and (2) to allow the program to
read directories created with long file names under Win95. Long file
names are NOT supported, but they no longer confuse the program.