home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / private / mpc93mar.zip / COMP.DAT < prev    next >
Text File  |  1993-02-15  |  22KB  |  566 lines

  1.     
  2.                        I Just got a Computer and I'm Lost
  3.  
  4.                                   Finding Files
  5.  
  6.                                  By Ken Johnson
  7.  
  8.         This month we'll look at some DOS commands and techniques to find
  9.         and  manage files in various subdirectories.  Let's start with  a
  10.         way to see the subdirectory structure itself:  the TREE command.
  11.  
  12.         TREE (DOS 4.0 & 5.0)
  13.  
  14.         An excellent command for viewing the directory structure of  your
  15.         hard  disk  is  TREE.  TREE will display a  graphical  "tree"  of
  16.         directories,  and optionally displaying the files in each  subdi-
  17.         rectory.   Though the TREE command has been available  since  DOS
  18.         2.0,  in versions before 4.0 it only prints the  directory  names
  19.         instead of a graphical display.  The format of the command is
  20.  
  21.              TREE [d:][path] [/F] [/A]
  22.  
  23.         where
  24.  
  25.         [d:] is the optional drive to display.
  26.  
  27.         [path] is the optional path to display at the "top" of the  tree.
  28.         If a path is not specified, DOS will use the default directory as
  29.         the topmost directory to diagram.
  30.  
  31.         [/F]  will show the names of all non hidden files in each  direc-
  32.         tory, beneath the directory name.
  33.  
  34.         [/A]  will display (and print) the output with  regular  keyboard
  35.         characters  rather than the high-ASCII box draw  characters,  for
  36.         example | and + instead of   and  .
  37.  
  38.         Here  is the output of TREE C:\, displaying the hard disk  direc-
  39.         tory structure:
  40.  
  41.              Directory PATH listing for Volume HD 80 MEG
  42.              Volume Serial Number is 16CF-7D4E
  43.              C:\
  44.              /-- 123FILES
  45.              |--\CCS
  46.              |  \--  DATABASE
  47.              |-- DOS
  48.              |-- DOSHELP
  49.              |-- PCTOOLS
  50.              |--\PDOX35
  51.              |  |--  KMEMO
  52.              |  |--  MBP
  53.              |  |--  PDOXDATA
  54.              |  \--  UTIL
  55.              |-- PROCOMM
  56.              |-- QEMM
  57.              |--\UTIL
  58.              |  |--  POWERUP
  59.              |  \--  INFOPLUS
  60.              |--\WINDOWS
  61.              |  \--  SYSTEM
  62.              |-----  TEMP
  63.              |-----  WINUTIL
  64.              |--\ZIP
  65.              |  |--  ARC
  66.              |  \--  LHA
  67.              \-  STACKER
  68.  
  69.         Since  it  is likely that the tree display will  scroll  off  the
  70.         screen,  you  may want to redirect the output of TREE  into  DOS'
  71.         MORE filter.  The MORE filter will take input from a file or from
  72.         the  output  of another command, and display it one screen  at  a
  73.         time.   At  the bottom of each screen, you'll see a  "--More  --"
  74.         prompt.  Press any key to continue and display the next screen.
  75.  
  76.         DOS has several symbols used to redirect input and output.  These
  77.         include:
  78.  
  79.              >    "With output to" --redirects output into a new file.
  80.                   The arrow "points" to the file receiving the output.
  81.              >>   "Appending output to" --redirects output into a file
  82.                   and appends to the end of the file if the file already
  83.                   exists.
  84.              <    "With input from" --redirects the contents of a file
  85.                   (or keystrokes from the keyboard) as input into a
  86.                   program.  The arrow "points" to the program receiving
  87.                   the input.
  88.              |    "Piping to" --sends the output of one program into
  89.                   another program as input.  The "flow" goes left to
  90.                   right.
  91.  
  92.         To  send the output from the TREE command into the  MORE  filter,
  93.         use the pipe symbol (|) like so:
  94.  
  95.              TREE C:\| MORE
  96.  
  97.         TREE's  output will be "piped" into the MORE program, which  dis-
  98.         plays it one screen at a time.
  99.  
  100.         Better yet, if you have the LIST program you can redirect  TREE's
  101.         output into that program for viewing.  The advantage of using the
  102.         LIST  program is that you can page up and down through  the  dis-
  103.         play; the MORE filter doesn't allow you to scroll backward.   You
  104.         can  also print from LIST.  When using redirection, use with  the
  105.         "/S"  switch  to tell LIST that it is browsing  redirected  input
  106.         rather than a file:
  107.  
  108.              TREE C:\| LIST /S
  109.  
  110.         You can also send the TREE output directly to your printer for  a
  111.         hard  copy, by redirecting the output to the printer  port.   Use
  112.         the DOS reserved name for the first parallel port, PRN:
  113.  
  114.              TREE C:\> PRN
  115.  
  116.         If your printer cannot print the high ASCII line draw characters,
  117.         use the "/A" switch to print with standard characters:
  118.  
  119.              TREE C:\/A > PRN
  120.  
  121.         You  can save the TREE output in a file, for editing or  incorpo-
  122.         rating into a document.  To do so, just redirect the output to  a
  123.         file, here called TREE.LST:
  124.  
  125.              TREE C:\> TREE.LST
  126.  
  127.         If  you have two hard drives, you can append the output from  the
  128.         second drive's TREE to the same file by using the double greater-
  129.         than signs:
  130.  
  131.              TREE C:\> TREE.LST
  132.              TREE D:\>> TREE.LST
  133.  
  134.         If  you want a listing of the files on the TREE display, use  the
  135.         "/F"  switch.  Under each subdirectory branch, DOS will  print  a
  136.         one-column list of all non hidden files in that directory.   Here
  137.         is an abbreviated sample from my hard drive:
  138.  
  139.              Directory PATH listing for Volume HD 80 MEG
  140.              Volume Serial Number is 16CF-7D4E
  141.              C:\
  142.                  OPT3.BAT
  143.              |   D5MACROS.BAT
  144.              |   ATDOSXL.SYS
  145.              |   AUTOEXEC.QDK
  146.              |   AUTOEXEC.BAT
  147.              |   AUTOEXEC.DOS
  148.              |   AUTOEXEC.KEJ
  149.              |   CONFIG.000
  150.                  CONFIG.SYS
  151.              :     (etc.)
  152.              :
  153.                  CCS
  154.              |       $EDUC.ZIP
  155.              |   |   BBS-HELP.ZIP
  156.              |   |   BOARD15.WP5
  157.              |   |   BULLET14.WP5
  158.              |   |   BYLAWS90.CCS
  159.              |   |   EDBUDGET.WK1
  160.              |   |   OPCHAIR
  161.                        (etc.)
  162.              :   :
  163.  
  164.                      DATABASE
  165.              |   |       ADDRESS.DB
  166.              |   |       ADDRESS.PX
  167.              |   |       DO-SKDB.SC
  168.              |   |       JUNK.DB
  169.              |   |         (etc.)
  170.              |   |
  171.              :   :
  172.         While  TREE gives you a good look at the subdirectory  structure,
  173.         it's  not great help with seeing file information and in  finding
  174.         particular  files.  Let's take a common case:  it's  likely  that
  175.         your hard drive is littered with .BAK files: Backup files created
  176.         when  editing.  Usually you don't need to keep these around,  and
  177.         they have a real tendency to proliferate.  Since they are  likely
  178.         to be in subdirectories all over the disk, it would be helpful to
  179.         be  able to see them all at once.  Let's look at ways to do  just
  180.         that.
  181.  
  182.         DIR /S (DOS 5.0)
  183.  
  184.         One  significant new feature is the "/S" switch, which tells  DOS
  185.         to  do  the DIRectory display in the default  directory  and  all
  186.         child  subdirectories.  This means that, executed from  the  root
  187.         directory, DIR can search the entire disk.
  188.  
  189.         To see all the backup files, use "*.BAK" as the filespec for  the
  190.         DIR command.  "*.BAK" will get us those files with any file  name
  191.         and an extension of BAK.  So the command:
  192.  
  193.  
  194.              DIR C:\*.BAK /S
  195.  
  196.  
  197.         will display (on my disk):
  198.  
  199.  
  200.               Volume in drive C is HD 80 MEG
  201.               Volume Serial Number is 16CF-7D4E
  202.  
  203.              Directory of C:\
  204.  
  205.              AUTOEXEC BAK      1697 05-06-92   9:29p
  206.              CONFIG   BAK       578 06-14-92  10:33a
  207.              D5MACROS BAK       650 06-03-92   9:15p
  208.              MIRROR   BAK    100864 05-03-92  11:38a
  209.                      4 file(s)     103789 bytes
  210.  
  211.  
  212.              Directory of C:\123FILES
  213.              COMMANDR BAK     13745 01-30-92  10:12p
  214.              DPR155   BAK     17642 09-15-91   3:02p
  215.              DPR161   BAK      9336 11-03-91  12:47p
  216.                      3 file(s)      40723 bytes
  217.  
  218.  
  219.              Directory of C:\PCTOOLS
  220.  
  221.              README   BAK      3840 09-08-90  10:13p
  222.                      1 file(s)       3840 bytes
  223.              Directory of C:\PDOX35
  224.  
  225.              INIT     BAK      4831 01-26-92   2:50p
  226.              PDOX     BAK       642 11-07-91   6:58p
  227.              PQ       BAK        43 03-09-92   6:49p
  228.              RETAIL   BAK       524 01-26-92   2:52p
  229.                      4 file(s)       6040 bytes
  230.  
  231.              Directory of C:\PDOX35\KMEMO
  232.  
  233.              KMCONFIG BAK        40 02-06-91  11:31a
  234.              MACRO    BAK       132 03-16-91  10:28p
  235.                      2 file(s)        172 bytes
  236.  
  237.              Directory of C:\PROCOMM
  238.              CCS      BAK       616 07-17-91   4:35p
  239.              CSERVE   BAK      1539 09-06-91  10:15p
  240.              DIALCOM  BAK       442 02-11-91   6:12p
  241.              SHELL    BAK       779 06-15-92  12:35p
  242.                      4 file(s)       3376 bytes
  243.  
  244.              Directory of C:\UTIL
  245.  
  246.              ARTICLES BAK      1154 05-26-92   7:48p
  247.              CHERYL   BAK       163 01-26-92  10:55a
  248.              RUN-G5   BAK       109 05-26-92   5:34p
  249.              TRAINING BAK       546 03-30-92   7:47p
  250.                      4 file(s)       1972 bytes
  251.  
  252.              Directory of C:\WINDOWS
  253.  
  254.              DRWATSON BAK      6462 04-25-92  11:14a
  255.              SYS-PM   BAK      1307 12-23-90   7:21p
  256.              SYSTEM   BAK      1353 04-11-92   6:34p
  257.              WIN      BAK     11292 04-26-92   4:14p
  258.                      4 file(s)      20414 bytes
  259.  
  260.              Total files listed:
  261.                     26 file(s)     180326 bytes
  262.                                  22211275 bytes free
  263.  
  264.         Again, if the list of files scrolls off the screen, use the  MORE
  265.         filter:
  266.  
  267.              DIR C:\*.BAK /S | MORE
  268.  
  269.  
  270.         or redirect into the LIST program:
  271.  
  272.              DIR C:\*.BAK /S | LIST /S
  273.  
  274.         This   DIR  display  includes  quite  a  few  blank   lines   and
  275.         header/footer  information that you may not really be  interested
  276.         in. It's also a little hard to read, since once you find the file
  277.         name, you have to look up a few lines so find the path name (that
  278.         is, what subdirectory the file is in).  Fortunately there is a
  279.         good solution, via the "/B" switch.
  280.  
  281.         The  "/B" (Bare) switch tells DIR not to display the  header  and
  282.         footer information, and display only the filename (no file  size,
  283.         date, or time).  When used with the "/S" switch, DIR will display
  284.         the full path name with the file name --in other words, the  full
  285.         filespec.  So to see a more readable display, try:
  286.  
  287.              DIR C:\*.BAK /S/B
  288.  
  289.         which produces:
  290.  
  291.              C:\AUTOEXEC.BAK
  292.              C:\CONFIG.BAK
  293.              C:\D5MACROS.BAK
  294.              C:\MIRROR.BAK
  295.              C:\123FILES\COMMANDR.BAK
  296.              C:\123FILES\DPR155.BAK
  297.              C:\123FILES\DPR161.BAK
  298.              C:\PCTOOLS\README.BAK
  299.              C:\PDOX35\INIT.BAK
  300.              C:\PDOX35\PDOX.BAK
  301.              C:\PDOX35\PQ.BAK
  302.              C:\PDOX35\RETAIL.BAK
  303.              C:\PDOX35\KMEMO\KMCONFIG.BAK
  304.              C:\PDOX35\KMEMO\MACRO.BAK
  305.              C:\PROCOMM\CCS.BAK
  306.              C:\PROCOMM\CSERVE.BAK
  307.              C:\PROCOMM\DIALCOM.BAK
  308.              C:\PROCOMM\SHELL.BAK
  309.              C:\UTIL\ARTICLES.BAK
  310.              C:\UTIL\CHERYL.BAK
  311.              C:\UTIL\RUN-G5.BAK
  312.              C:\UTIL\TRAINING.BAK
  313.              C:\WINDOWS\DRWATSON.BAK
  314.              C:\WINDOWS\SYS-PM.BAK
  315.              C:\WINDOWS\SYSTEM.BAK
  316.              C:\WINDOWS\WIN.BAK
  317.  
  318.         Again, for a long list of files, use the MORE filter or  redirec-
  319.         tion into the LIST program:
  320.  
  321.  
  322.              DIR C:\*.BAK /S/B | MORE
  323.              DIR C:\*.BAK /S/B | LIST /S
  324.  
  325.         ATTRIB /S (DOS 3.3+)
  326.  
  327.         If you don't have DOS 5.0 but do have version 3.3 or 4.0, you can
  328.         use another command to search through subdirectories --ATTRIB.
  329.  
  330.         The ATTRIB command is used to view and optionally change (depend-
  331.         ing  on the DOS version) four of a file's attributes.   The  four
  332.         attributes are Hidden, System, Archive, and Read-Only.  DOS 5.0's
  333.         ATTRIB  includes the "/S" switch to search the current  directory
  334.         and  all  child subdirectories.  The full format  of  the  ATTRIB
  335.         command is:
  336.  
  337.              ATTRIB [+A] [+R] [+H] [+S] [filespec] [/S]
  338.  
  339.         where:
  340.  
  341.         [+A]  turns on (+) or off (-) the Archive attribute (DOS 3.2  and
  342.         above).
  343.  
  344.         [+R] turns on (+) or off (-) the Read-Only attribute (DOS 3.0 and
  345.         above).
  346.  
  347.         [+H] turns on (+) or off (-) the Hidden attribute (DOS 5.0).
  348.  
  349.         [+S] turns on (+) or off (-) the System attribute (DOS 5.0).
  350.  
  351.         [filespec] is the optional filename; if not included, ATTRIB will
  352.         act upon every file in the directory (*.*).
  353.  
  354.         [/S] specifies to act upon files in the current directory and all
  355.         child subdirectories
  356.  
  357.         So to display all the .BAK files on the C: drive, use:
  358.  
  359.         ATTRIB C:\*.BAK /S
  360.  
  361.         to produce:
  362.  
  363.                           C:\123FILES\COMMANDR.BAK
  364.                           C:\123FILES\DPR155.BAK
  365.                           C:\123FILES\DPR161.BAK
  366.                           C:\PCTOOLS\README.BAK
  367.                           C:\PDOX35\KMEMO\KMCONFIG.BAK
  368.                           C:\PDOX35\KMEMO\MACRO.BAK
  369.                           C:\PDOX35\INIT.BAK
  370.                           C:\PDOX35\PDOX.BAK
  371.                A          C:\PDOX35\PQ.BAK
  372.                           C:\PDOX35\RETAIL.BAK
  373.                           C:\PROCOMM\CCS.BAK
  374.                           C:\PROCOMM\CSERVE.BAK
  375.                           C:\PROCOMM\DIALCOM.BAK
  376.                A          C:\PROCOMM\SHELL.BAK
  377.                A          C:\UTIL\ARTICLES.BAK
  378.                A          C:\UTIL\RUN-G5.BAK
  379.                           C:\UTIL\CHERYL.BAK
  380.                A          C:\UTIL\TRAINING.BAK
  381.                A          C:\WINDOWS\DRWATSON.BAK
  382.                           C:\WINDOWS\SYS-PM.BAK
  383.                A          C:\WINDOWS\SYSTEM.BAK
  384.                A          C:\WINDOWS\WIN.BAK
  385.                           C:\CONFIG.BAK
  386.                A          C:\AUTOEXEC.BAK
  387.                A          C:\D5MACROS.BAK
  388.                A    R     C:\MIRROR.BAK
  389.  
  390.         The spaces before each filespec is where the attributes for  each
  391.         of  the individual files are displayed:  A S H R.  Just like  the
  392.         examples  above, you can use the MORE filter, redirect  into  the
  393.         LIST program, or output to the printer or a file.
  394.  
  395.         CHKDSK /V
  396.  
  397.         There  is  still  another way to find  files,  by  using  CHKDSK.
  398.         You're  probably saying, "CHKDSK, that is for fixing  disk  prob-
  399.         lems."  Well CHKDSK has a secret.  It can also display file names
  400.         by  using the "/V" (Verbose) switch.  "/V" will display all  file
  401.         names,  including hidden files.  In fact, before DOS 5.0,  CHKDSK
  402.         /V was the only DOS command that would show hidden files.
  403.  
  404.         The full syntax for CHKDSK is:
  405.  
  406.                   CHKDSK [filespec] [/F] [/V]
  407.  
  408.         where
  409.  
  410.         [/F] tells CHKDSK to fix any disk problems it encounters.
  411.  
  412.         [/V] displays all filenames as it checks the disk.
  413.  
  414.         [filespec]  is  an optional path and file  name.   If  specified,
  415.         CHKDSK will check if that file (or all files matching a  wildcard
  416.         filespec) is stored in contiguous sectors on the disk.  Note:  if
  417.         you use a filespec with the /V switch, CHKDSK will still  display
  418.         ALL files on the disk.
  419.  
  420.         Using CHKDSK to find files is complicated because the output  may
  421.         not  be in the format you expect.  CHKDSK /V will  display  files
  422.         based  on  their physical order in the directory,  not  in  their
  423.         "logical" subdirectory order.  This means that files in the  same
  424.         subdirectory  may  not  be listed together.   Also,  CHKDSK  will
  425.         always go through the process of checking the entire disk  (which
  426.         slows  getting  the output) and producing a report  on  file  and
  427.         memory use.
  428.  
  429.         But  the  biggest problem with using CHKDSK /V to find  files  is
  430.         that  it  displays all the files; you can't subset like  you  can
  431.         with  DIR or ATTRIB.  The solution is to use another DOS  filter,
  432.         FIND.   By "piping" the CHKDSK output into the FIND  program,  we
  433.         can end with only the file names we're interested in.
  434.  
  435.         The  FIND program takes input and, line by line, tries to find  a
  436.         specified  string.   If found, that line is output; if  not,  the
  437.         line  is  dropped.  The specified string is put in  quotes.   The
  438.         FIND syntax is:
  439.  
  440.                   FIND [/V] [/C] [/N] [/I] "string" filespec
  441.  
  442.         where:
  443.         [filespec]  is the text file to search.  You can list  more  than
  444.         one  filename, but wildcard filespecs are NOT allowed.   You  can
  445.         also use redirection to specify an input file
  446.  
  447.         (e.g., < INPUT.TXT)
  448.  
  449.         or a file to output the result to
  450.  
  451.         (e.g., > FIND.LST).
  452.  
  453.         You can also "pipe" input into FIND.
  454.  
  455.         [string] is the string of text to find; it must be in quotes.
  456.  
  457.         FIND  is case sensitive unless you use the "/I" switch, which  is
  458.         only available in DOS 5.0.
  459.  
  460.         [/V]  is a reverse find; FIND will only output lines that do  not
  461.         contain the string text.
  462.  
  463.         [/C]  outputs  only a Count of lines containing the  string;  the
  464.         lines themselves are not output.
  465.  
  466.         [/N] outputs the line Number before each matching line.
  467.  
  468.         [/I]  instructs  FIND to do a case Insensitive  search  (DOS  5.0
  469.         only).
  470.  
  471.         In  our  example, we'll pipe (|) the output from CHKDSK  /V  into
  472.         FIND,  and search for ".BAK".  Remember that DOS file  names  are
  473.         always in capital letters:
  474.  
  475.              CHKDSK C: /V | FIND ".BAK"
  476.  
  477.         This produces:
  478.  
  479.              C:\123FILES\COMMANDR.BAK
  480.              C:\123FILES\DPR155.BAK
  481.              C:\123FILES\DPR161.BAK
  482.              C:\AUTOEXEC.BAK
  483.              C:\CONFIG.BAK
  484.              C:\PCTOOLS\README.BAK
  485.              C:\PDOX35\INIT.BAK
  486.              C:\PDOX35\KMEMO\KMCONFIG.BAK
  487.              C:\PDOX35\PDOX.BAK
  488.              C:\PDOX35\PQ.BAK
  489.              C:\PDOX35\RETAIL.BAK
  490.              C:\PROCOMM\CCS.BAK
  491.              C:\PROCOMM\CSERVE.BAK
  492.              C:\PROCOMM\DIALCOM.BAK
  493.              C:\PDOX35\KMEMO\MACRO.BAK
  494.              C:\PROCOMM\SHELL.BAK
  495.              C:\UTIL\ARTICLES.BAK
  496.              C:\UTIL\CHERYL.BAK
  497.              C:\UTIL\RUN-G5.BAK
  498.              C:\UTIL\TRAINING.BAK
  499.              C:\WINDOWS\DRWATSON.BAK
  500.              C:\WINDOWS\SYS-PM.BAK
  501.              C:\WINDOWS\SYSTEM.BAK
  502.              C:\WINDOWS\WIN.BAK
  503.              C:\D5MACROS.BAK
  504.              C:\MIRROR.BAK
  505.  
  506.  
  507.         Unfortunately,  the list might still not be in a logical,  subdi-
  508.         rectory  order.  Note in this example that two of the .BAK  files
  509.         in  the  root are toward the top of the list and two are  at  the
  510.         bottom.  But there is yet another DOS filter to come to our  aid,
  511.         the SORT program.
  512.  
  513.         SORT  will take input and sort it line by line.  You can  specify
  514.         the  starting sort position; otherwise SORT will begin  with  the
  515.         first character.
  516.  
  517.         The syntax is:
  518.  
  519.         SORT [/R] [/+n] < infile [ > outfile]
  520.  
  521.         where:
  522.  
  523.         [infile]  is the filespec containing the input to sort.  You  can
  524.         also  pipe  input into SORT, as well as pipe SORT's  output  into
  525.         another program.
  526.  
  527.         [outfile] is the optional file to contain the sorted output.   If
  528.         not  specified,  and if you don't pipe the  output  into  another
  529.         program, SORT will output to the screen.
  530.  
  531.         [/R]  requests a Reverse sort; the input is sorted in  descending
  532.         order (Z-A, then 9-0).
  533.  
  534.         [/+n]  specifies  to start sorting at the nth character  of  each
  535.         line.   For example, if you wanted to start sorting on  the  10th
  536.         character, you would specify /+10.
  537.  
  538.         So our command now becomes:
  539.  
  540.              CHKDSK /V | FIND ".BAK" | SORT
  541.  
  542.         Again,  if the display is too long we can continue the "pipe"  by
  543.         redirecting  SORT's output into the MORE filter or the LIST  pro-
  544.         gram:
  545.  
  546.              CHKDSK /V | FIND ".BAK" | SORT | MORE
  547.              CHKDSK /V | FIND ".BAK" | SORT | LIST /S
  548.  
  549.         Since these commands are complicated and take a while to type in,
  550.         they're  a good candidate for a batch file.  We'll look  at  that
  551.         batch file next month, along with ways of deleting all these .BAK
  552.         files now that we've found them.
  553.  
  554.                ===================================================
  555.  
  556.  
  557.         Author Information:  Ken Johnson is Training and Support  Manager
  558.         at  the  law firm of Mayer, Brown & Platt in Chicago.   He  is  a
  559.         contributing  editor  to Hard-Copy, the Journal  of  the  Chicago
  560.         Computer Society, and a contributing writer to the Lawyers Micro-
  561.         Computer Users Group newsletter.
  562.  
  563.  
  564.  
  565.                                   *  *  *  *  *
  566.