home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 9
/
MEDIASHARE_09.ISO
/
private
/
mpc93mar.zip
/
COMP.DAT
< prev
next >
Wrap
Text File
|
1993-02-15
|
22KB
|
566 lines
I Just got a Computer and I'm Lost
Finding Files
By Ken Johnson
This month we'll look at some DOS commands and techniques to find
and manage files in various subdirectories. Let's start with a
way to see the subdirectory structure itself: the TREE command.
TREE (DOS 4.0 & 5.0)
An excellent command for viewing the directory structure of your
hard disk is TREE. TREE will display a graphical "tree" of
directories, and optionally displaying the files in each subdi-
rectory. Though the TREE command has been available since DOS
2.0, in versions before 4.0 it only prints the directory names
instead of a graphical display. The format of the command is
TREE [d:][path] [/F] [/A]
where
[d:] is the optional drive to display.
[path] is the optional path to display at the "top" of the tree.
If a path is not specified, DOS will use the default directory as
the topmost directory to diagram.
[/F] will show the names of all non hidden files in each direc-
tory, beneath the directory name.
[/A] will display (and print) the output with regular keyboard
characters rather than the high-ASCII box draw characters, for
example | and + instead of and .
Here is the output of TREE C:\, displaying the hard disk direc-
tory structure:
Directory PATH listing for Volume HD 80 MEG
Volume Serial Number is 16CF-7D4E
C:\
/-- 123FILES
|--\CCS
| \-- DATABASE
|-- DOS
|-- DOSHELP
|-- PCTOOLS
|--\PDOX35
| |-- KMEMO
| |-- MBP
| |-- PDOXDATA
| \-- UTIL
|-- PROCOMM
|-- QEMM
|--\UTIL
| |-- POWERUP
| \-- INFOPLUS
|--\WINDOWS
| \-- SYSTEM
|----- TEMP
|----- WINUTIL
|--\ZIP
| |-- ARC
| \-- LHA
\- STACKER
Since it is likely that the tree display will scroll off the
screen, you may want to redirect the output of TREE into DOS'
MORE filter. The MORE filter will take input from a file or from
the output of another command, and display it one screen at a
time. At the bottom of each screen, you'll see a "--More --"
prompt. Press any key to continue and display the next screen.
DOS has several symbols used to redirect input and output. These
include:
> "With output to" --redirects output into a new file.
The arrow "points" to the file receiving the output.
>> "Appending output to" --redirects output into a file
and appends to the end of the file if the file already
exists.
< "With input from" --redirects the contents of a file
(or keystrokes from the keyboard) as input into a
program. The arrow "points" to the program receiving
the input.
| "Piping to" --sends the output of one program into
another program as input. The "flow" goes left to
right.
To send the output from the TREE command into the MORE filter,
use the pipe symbol (|) like so:
TREE C:\| MORE
TREE's output will be "piped" into the MORE program, which dis-
plays it one screen at a time.
Better yet, if you have the LIST program you can redirect TREE's
output into that program for viewing. The advantage of using the
LIST program is that you can page up and down through the dis-
play; the MORE filter doesn't allow you to scroll backward. You
can also print from LIST. When using redirection, use with the
"/S" switch to tell LIST that it is browsing redirected input
rather than a file:
TREE C:\| LIST /S
You can also send the TREE output directly to your printer for a
hard copy, by redirecting the output to the printer port. Use
the DOS reserved name for the first parallel port, PRN:
TREE C:\> PRN
If your printer cannot print the high ASCII line draw characters,
use the "/A" switch to print with standard characters:
TREE C:\/A > PRN
You can save the TREE output in a file, for editing or incorpo-
rating into a document. To do so, just redirect the output to a
file, here called TREE.LST:
TREE C:\> TREE.LST
If you have two hard drives, you can append the output from the
second drive's TREE to the same file by using the double greater-
than signs:
TREE C:\> TREE.LST
TREE D:\>> TREE.LST
If you want a listing of the files on the TREE display, use the
"/F" switch. Under each subdirectory branch, DOS will print a
one-column list of all non hidden files in that directory. Here
is an abbreviated sample from my hard drive:
Directory PATH listing for Volume HD 80 MEG
Volume Serial Number is 16CF-7D4E
C:\
OPT3.BAT
| D5MACROS.BAT
| ATDOSXL.SYS
| AUTOEXEC.QDK
| AUTOEXEC.BAT
| AUTOEXEC.DOS
| AUTOEXEC.KEJ
| CONFIG.000
CONFIG.SYS
: (etc.)
:
CCS
| $EDUC.ZIP
| | BBS-HELP.ZIP
| | BOARD15.WP5
| | BULLET14.WP5
| | BYLAWS90.CCS
| | EDBUDGET.WK1
| | OPCHAIR
(etc.)
: :
DATABASE
| | ADDRESS.DB
| | ADDRESS.PX
| | DO-SKDB.SC
| | JUNK.DB
| | (etc.)
| |
: :
While TREE gives you a good look at the subdirectory structure,
it's not great help with seeing file information and in finding
particular files. Let's take a common case: it's likely that
your hard drive is littered with .BAK files: Backup files created
when editing. Usually you don't need to keep these around, and
they have a real tendency to proliferate. Since they are likely
to be in subdirectories all over the disk, it would be helpful to
be able to see them all at once. Let's look at ways to do just
that.
DIR /S (DOS 5.0)
One significant new feature is the "/S" switch, which tells DOS
to do the DIRectory display in the default directory and all
child subdirectories. This means that, executed from the root
directory, DIR can search the entire disk.
To see all the backup files, use "*.BAK" as the filespec for the
DIR command. "*.BAK" will get us those files with any file name
and an extension of BAK. So the command:
DIR C:\*.BAK /S
will display (on my disk):
Volume in drive C is HD 80 MEG
Volume Serial Number is 16CF-7D4E
Directory of C:\
AUTOEXEC BAK 1697 05-06-92 9:29p
CONFIG BAK 578 06-14-92 10:33a
D5MACROS BAK 650 06-03-92 9:15p
MIRROR BAK 100864 05-03-92 11:38a
4 file(s) 103789 bytes
Directory of C:\123FILES
COMMANDR BAK 13745 01-30-92 10:12p
DPR155 BAK 17642 09-15-91 3:02p
DPR161 BAK 9336 11-03-91 12:47p
3 file(s) 40723 bytes
Directory of C:\PCTOOLS
README BAK 3840 09-08-90 10:13p
1 file(s) 3840 bytes
Directory of C:\PDOX35
INIT BAK 4831 01-26-92 2:50p
PDOX BAK 642 11-07-91 6:58p
PQ BAK 43 03-09-92 6:49p
RETAIL BAK 524 01-26-92 2:52p
4 file(s) 6040 bytes
Directory of C:\PDOX35\KMEMO
KMCONFIG BAK 40 02-06-91 11:31a
MACRO BAK 132 03-16-91 10:28p
2 file(s) 172 bytes
Directory of C:\PROCOMM
CCS BAK 616 07-17-91 4:35p
CSERVE BAK 1539 09-06-91 10:15p
DIALCOM BAK 442 02-11-91 6:12p
SHELL BAK 779 06-15-92 12:35p
4 file(s) 3376 bytes
Directory of C:\UTIL
ARTICLES BAK 1154 05-26-92 7:48p
CHERYL BAK 163 01-26-92 10:55a
RUN-G5 BAK 109 05-26-92 5:34p
TRAINING BAK 546 03-30-92 7:47p
4 file(s) 1972 bytes
Directory of C:\WINDOWS
DRWATSON BAK 6462 04-25-92 11:14a
SYS-PM BAK 1307 12-23-90 7:21p
SYSTEM BAK 1353 04-11-92 6:34p
WIN BAK 11292 04-26-92 4:14p
4 file(s) 20414 bytes
Total files listed:
26 file(s) 180326 bytes
22211275 bytes free
Again, if the list of files scrolls off the screen, use the MORE
filter:
DIR C:\*.BAK /S | MORE
or redirect into the LIST program:
DIR C:\*.BAK /S | LIST /S
This DIR display includes quite a few blank lines and
header/footer information that you may not really be interested
in. It's also a little hard to read, since once you find the file
name, you have to look up a few lines so find the path name (that
is, what subdirectory the file is in). Fortunately there is a
good solution, via the "/B" switch.
The "/B" (Bare) switch tells DIR not to display the header and
footer information, and display only the filename (no file size,
date, or time). When used with the "/S" switch, DIR will display
the full path name with the file name --in other words, the full
filespec. So to see a more readable display, try:
DIR C:\*.BAK /S/B
which produces:
C:\AUTOEXEC.BAK
C:\CONFIG.BAK
C:\D5MACROS.BAK
C:\MIRROR.BAK
C:\123FILES\COMMANDR.BAK
C:\123FILES\DPR155.BAK
C:\123FILES\DPR161.BAK
C:\PCTOOLS\README.BAK
C:\PDOX35\INIT.BAK
C:\PDOX35\PDOX.BAK
C:\PDOX35\PQ.BAK
C:\PDOX35\RETAIL.BAK
C:\PDOX35\KMEMO\KMCONFIG.BAK
C:\PDOX35\KMEMO\MACRO.BAK
C:\PROCOMM\CCS.BAK
C:\PROCOMM\CSERVE.BAK
C:\PROCOMM\DIALCOM.BAK
C:\PROCOMM\SHELL.BAK
C:\UTIL\ARTICLES.BAK
C:\UTIL\CHERYL.BAK
C:\UTIL\RUN-G5.BAK
C:\UTIL\TRAINING.BAK
C:\WINDOWS\DRWATSON.BAK
C:\WINDOWS\SYS-PM.BAK
C:\WINDOWS\SYSTEM.BAK
C:\WINDOWS\WIN.BAK
Again, for a long list of files, use the MORE filter or redirec-
tion into the LIST program:
DIR C:\*.BAK /S/B | MORE
DIR C:\*.BAK /S/B | LIST /S
ATTRIB /S (DOS 3.3+)
If you don't have DOS 5.0 but do have version 3.3 or 4.0, you can
use another command to search through subdirectories --ATTRIB.
The ATTRIB command is used to view and optionally change (depend-
ing on the DOS version) four of a file's attributes. The four
attributes are Hidden, System, Archive, and Read-Only. DOS 5.0's
ATTRIB includes the "/S" switch to search the current directory
and all child subdirectories. The full format of the ATTRIB
command is:
ATTRIB [+A] [+R] [+H] [+S] [filespec] [/S]
where:
[+A] turns on (+) or off (-) the Archive attribute (DOS 3.2 and
above).
[+R] turns on (+) or off (-) the Read-Only attribute (DOS 3.0 and
above).
[+H] turns on (+) or off (-) the Hidden attribute (DOS 5.0).
[+S] turns on (+) or off (-) the System attribute (DOS 5.0).
[filespec] is the optional filename; if not included, ATTRIB will
act upon every file in the directory (*.*).
[/S] specifies to act upon files in the current directory and all
child subdirectories
So to display all the .BAK files on the C: drive, use:
ATTRIB C:\*.BAK /S
to produce:
C:\123FILES\COMMANDR.BAK
C:\123FILES\DPR155.BAK
C:\123FILES\DPR161.BAK
C:\PCTOOLS\README.BAK
C:\PDOX35\KMEMO\KMCONFIG.BAK
C:\PDOX35\KMEMO\MACRO.BAK
C:\PDOX35\INIT.BAK
C:\PDOX35\PDOX.BAK
A C:\PDOX35\PQ.BAK
C:\PDOX35\RETAIL.BAK
C:\PROCOMM\CCS.BAK
C:\PROCOMM\CSERVE.BAK
C:\PROCOMM\DIALCOM.BAK
A C:\PROCOMM\SHELL.BAK
A C:\UTIL\ARTICLES.BAK
A C:\UTIL\RUN-G5.BAK
C:\UTIL\CHERYL.BAK
A C:\UTIL\TRAINING.BAK
A C:\WINDOWS\DRWATSON.BAK
C:\WINDOWS\SYS-PM.BAK
A C:\WINDOWS\SYSTEM.BAK
A C:\WINDOWS\WIN.BAK
C:\CONFIG.BAK
A C:\AUTOEXEC.BAK
A C:\D5MACROS.BAK
A R C:\MIRROR.BAK
The spaces before each filespec is where the attributes for each
of the individual files are displayed: A S H R. Just like the
examples above, you can use the MORE filter, redirect into the
LIST program, or output to the printer or a file.
CHKDSK /V
There is still another way to find files, by using CHKDSK.
You're probably saying, "CHKDSK, that is for fixing disk prob-
lems." Well CHKDSK has a secret. It can also display file names
by using the "/V" (Verbose) switch. "/V" will display all file
names, including hidden files. In fact, before DOS 5.0, CHKDSK
/V was the only DOS command that would show hidden files.
The full syntax for CHKDSK is:
CHKDSK [filespec] [/F] [/V]
where
[/F] tells CHKDSK to fix any disk problems it encounters.
[/V] displays all filenames as it checks the disk.
[filespec] is an optional path and file name. If specified,
CHKDSK will check if that file (or all files matching a wildcard
filespec) is stored in contiguous sectors on the disk. Note: if
you use a filespec with the /V switch, CHKDSK will still display
ALL files on the disk.
Using CHKDSK to find files is complicated because the output may
not be in the format you expect. CHKDSK /V will display files
based on their physical order in the directory, not in their
"logical" subdirectory order. This means that files in the same
subdirectory may not be listed together. Also, CHKDSK will
always go through the process of checking the entire disk (which
slows getting the output) and producing a report on file and
memory use.
But the biggest problem with using CHKDSK /V to find files is
that it displays all the files; you can't subset like you can
with DIR or ATTRIB. The solution is to use another DOS filter,
FIND. By "piping" the CHKDSK output into the FIND program, we
can end with only the file names we're interested in.
The FIND program takes input and, line by line, tries to find a
specified string. If found, that line is output; if not, the
line is dropped. The specified string is put in quotes. The
FIND syntax is:
FIND [/V] [/C] [/N] [/I] "string" filespec
where:
[filespec] is the text file to search. You can list more than
one filename, but wildcard filespecs are NOT allowed. You can
also use redirection to specify an input file
(e.g., < INPUT.TXT)
or a file to output the result to
(e.g., > FIND.LST).
You can also "pipe" input into FIND.
[string] is the string of text to find; it must be in quotes.
FIND is case sensitive unless you use the "/I" switch, which is
only available in DOS 5.0.
[/V] is a reverse find; FIND will only output lines that do not
contain the string text.
[/C] outputs only a Count of lines containing the string; the
lines themselves are not output.
[/N] outputs the line Number before each matching line.
[/I] instructs FIND to do a case Insensitive search (DOS 5.0
only).
In our example, we'll pipe (|) the output from CHKDSK /V into
FIND, and search for ".BAK". Remember that DOS file names are
always in capital letters:
CHKDSK C: /V | FIND ".BAK"
This produces:
C:\123FILES\COMMANDR.BAK
C:\123FILES\DPR155.BAK
C:\123FILES\DPR161.BAK
C:\AUTOEXEC.BAK
C:\CONFIG.BAK
C:\PCTOOLS\README.BAK
C:\PDOX35\INIT.BAK
C:\PDOX35\KMEMO\KMCONFIG.BAK
C:\PDOX35\PDOX.BAK
C:\PDOX35\PQ.BAK
C:\PDOX35\RETAIL.BAK
C:\PROCOMM\CCS.BAK
C:\PROCOMM\CSERVE.BAK
C:\PROCOMM\DIALCOM.BAK
C:\PDOX35\KMEMO\MACRO.BAK
C:\PROCOMM\SHELL.BAK
C:\UTIL\ARTICLES.BAK
C:\UTIL\CHERYL.BAK
C:\UTIL\RUN-G5.BAK
C:\UTIL\TRAINING.BAK
C:\WINDOWS\DRWATSON.BAK
C:\WINDOWS\SYS-PM.BAK
C:\WINDOWS\SYSTEM.BAK
C:\WINDOWS\WIN.BAK
C:\D5MACROS.BAK
C:\MIRROR.BAK
Unfortunately, the list might still not be in a logical, subdi-
rectory order. Note in this example that two of the .BAK files
in the root are toward the top of the list and two are at the
bottom. But there is yet another DOS filter to come to our aid,
the SORT program.
SORT will take input and sort it line by line. You can specify
the starting sort position; otherwise SORT will begin with the
first character.
The syntax is:
SORT [/R] [/+n] < infile [ > outfile]
where:
[infile] is the filespec containing the input to sort. You can
also pipe input into SORT, as well as pipe SORT's output into
another program.
[outfile] is the optional file to contain the sorted output. If
not specified, and if you don't pipe the output into another
program, SORT will output to the screen.
[/R] requests a Reverse sort; the input is sorted in descending
order (Z-A, then 9-0).
[/+n] specifies to start sorting at the nth character of each
line. For example, if you wanted to start sorting on the 10th
character, you would specify /+10.
So our command now becomes:
CHKDSK /V | FIND ".BAK" | SORT
Again, if the display is too long we can continue the "pipe" by
redirecting SORT's output into the MORE filter or the LIST pro-
gram:
CHKDSK /V | FIND ".BAK" | SORT | MORE
CHKDSK /V | FIND ".BAK" | SORT | LIST /S
Since these commands are complicated and take a while to type in,
they're a good candidate for a batch file. We'll look at that
batch file next month, along with ways of deleting all these .BAK
files now that we've found them.
===================================================
Author Information: Ken Johnson is Training and Support Manager
at the law firm of Mayer, Brown & Platt in Chicago. He is a
contributing editor to Hard-Copy, the Journal of the Chicago
Computer Society, and a contributing writer to the Lawyers Micro-
Computer Users Group newsletter.
* * * * *