home *** CD-ROM | disk | FTP | other *** search
/ Hacker Chronicles 2 / HACKER2.BIN / 102.TECH03.TXT < prev    next >
Text File  |  1993-07-30  |  21KB  |  486 lines

  1.  
  2.                           Organizing Your Hard Drive
  3.  
  4.                    By Ken Johnson, Chicago Computer Society
  5.  
  6.  
  7.      In last month's column we looked at files and file names.  This
  8.      month we'll discuss how files are organized on a disk.  Your
  9.      computer's hard disk can store many files, but finding and using
  10.      specific files (whether programs or data) can be difficult
  11.      without some sort of organization.  Luckily DOS provides such
  12.      organization via a "subdirectory structure."
  13.  
  14.      A physical disk is organized into a logical structure consisting
  15.      of a root directory (designated by a backslash "\") and various
  16.      named subdirectories which branch off the root.  Graphically, the
  17.      directory structure looks like an upside-down tree.  This tree-
  18.      structured directory system allows you to categorize your files,
  19.      placing like files into the same directory.  Most users divide
  20.      their hard disk into several directories grouped around similar
  21.      types of applications or data:
  22.  
  23.                                     C:\ (ROOT)
  24.                        ┌─────────┬──────┴───────┬──────────┐
  25.                     123R23      WP51           UTIL       DOS
  26.                 ┌──────┘         │              │          │
  27.             ┌───┴────┐       ┌───┴───┐         BIN       NORTON
  28.             │        │       │       │
  29.           BUDGET   TAXES   MEMOS  ARTICLES
  30.  
  31.      Thus, a directory structure grows like a tree.  The root
  32.      directory contains all the main "branches" and each branch may
  33.      contain its own branches.  The "leaves" of the tree are the
  34.      files:
  35.  
  36.                             C:\ (ROOT)
  37.                     ┌─ ─ ─ ─ ┴ ─ ─
  38.                    WP51
  39.          ─ ─ ─┬─────┴ ─ ─
  40.             MEMOS
  41.               │
  42.          MEMO5-4.92
  43.          MKTPLAN.FEB
  44.          2DO.LST
  45.          CLIENTS.LTR
  46.  
  47.      The file MEMO5-4.92 is in the MEMOS subdirectory, which is in the
  48.      WP51 subdirectory, which is in the root directory of the C:
  49.      drive.  The sequence of directories leading from the root to the
  50.      file is called the path.
  51.  
  52.      As we discussed in last month's column, to find a file DOS needs
  53.      to know the path to the file, also that file's name and
  54.      extension.  This is called the filespec.  The filespec for the
  55.      file above is:
  56.  
  57.           C:\WP51\MEMOS\MEMO5-4.92
  58.  
  59.      where:
  60.  
  61.      "C:\" indicates the root directory of the C: drive,
  62.  
  63.      "WP51\MEMOS\" indicates the MEMOS subdirectory of the WP51
  64.      subdirectory,
  65.  
  66.      and "MEMO5-4.92" is the file name and extension.
  67.  
  68.      Organization of files into a logical subdirectory structure is
  69.      very important.  Most application programs will create their own
  70.      subdirectories and install their files there.  However, often you
  71.      will need to decide where to store your data files.  A general
  72.      rule is to store your data in a separate subdirectory from the
  73.      program that created that data.  For example, don't store your
  74.      WordPerfect documents with the WordPerfect programs.
  75.  
  76.      The basic reason for storing data separate from programs is that
  77.      you care much more about the data than the programs.  By keeping
  78.      the data separate, it is much easier to backup those important
  79.      files and more likely that you will do it.  Data subdirectories
  80.      tend to be smaller, and often you can copy all the files onto a
  81.      single high density floppy using COPY or XCOPY.  This can easily
  82.      be automated in a batch file, letting you make backup copies of
  83.      data files without having to really think about it.
  84.  
  85.  
  86.      The Root Directory
  87.  
  88.      When you boot up your computer, you are logged into the root
  89.      directory of the hard drive C: (or the A: drive if you've started
  90.      with a DOS disk in the A: drive).  The root directory doesn't
  91.      really have a name, rather the backslash character "\" stands for
  92.      the root directory.  From the root, you use the CD (change
  93.      directory) to move to the subdirectories.
  94.  
  95.      One sure sign of a disorganized hard drive is a root directory
  96.      full of files.  The root directory need only contain a few
  97.      necessary files ("necessary" because DOS will look for them in
  98.      the root of the boot drive), including:
  99.  
  100.      AUTOEXEC.BAT The AUTOmatically EXECute "startup" BATch file
  101.      containing commands to execute whenever the computer starts up.
  102.      CONFIG.SYS The file specifying CONFIGuration of your SYStem,
  103.      which loads device drivers and configures memory.
  104.  
  105.      The root will also contain the two hidden DOS files (IBMBIO.COM &
  106.      IBMDOS.COM, or IO.SYS & MSDOS.SYS), and a hidden file containing
  107.      the volume label of the disk.  Many people keep COMMAND.COM, the
  108.      command interpreter, in the root directory but this is not
  109.      required.  The SHELL= statement in CONFIG.SYS can tell DOS where
  110.      to find COMMAND.COM if not in the root directory.
  111.  
  112.      (The SHELL statement in CONFIG.SYS tells DOS the name of the
  113.      command interpreter (usually COMMAND.COM), its location, and the
  114.      size of the DOS environment.  SHELL was discussed in the January
  115.      1992 and the September 1991 Hard-Copy Beginner's Columns.)
  116.  
  117.      There is a limit on the number of files that can exist in the
  118.      root directory of any disk.  The maximums are 112 files on a
  119.      Double Density, Double Sided 5¼ or 3½ floppy disk, 224 files on a
  120.      high density 5¼ or 3½ disk, and 512 files on most hard disks.
  121.      However, there are no limits on the number of files in a
  122.      subdirectory.  Subdirectories are just files that keep track of
  123.      other files, and like any file can grow if there is disk space.
  124.  
  125.  
  126.      Subdirectories
  127.  
  128.      Most of DOS' work is done in subdirectories.  As mentioned above,
  129.      there is no limit on the number of files in a subdirectory, nor
  130.      is there a limit to the number of subdirectories you can have on
  131.      a hard disk.  There is however a limit of the number of
  132.      subdirectory levels you can have, based on the length of the
  133.      subdirectory names.  DOS limits a directory path to 63
  134.      characters, measured from the root to the bottom level.  If you
  135.      use 8-character subdirectory names, this gives you a limit of
  136.      about seven levels.  In practice, you won't have to worry about
  137.      this limitation since most users seldom have subdirectories more
  138.      than 3-4 levels deep.
  139.  
  140.      The most important thing to remember about the directory
  141.      structure is that you can only be in one directory at a time.
  142.      This is called the "default directory," meaning that unless you
  143.      tell DOS otherwise, it will perform operations against files in
  144.      that directory.  You can tell DOS to look in other directories by
  145.      using the PATH statement, and move to other subdirectories with
  146.      the CD command.  We'll look at these commands below.
  147.  
  148.      There are a couple of different ways to view subdirectories with
  149.      the DIR command.  If you have DOS 5.0, you can use the /AD switch
  150.      to show only directories.  Another method is to use "DIR *.",
  151.      that will show all files without extensions.  Since most
  152.      subdirectories don't have extensions (though there is no reason
  153.      they can't) and most files do have extensions, this command will
  154.      usually show all the subdirectories one level down from where you
  155.      are.
  156.  
  157.      For example, here is the output from "DIR /AD" on the root
  158.      directory of my D: drive:
  159.  
  160.      Volume in drive D is STACVOL_DSK
  161.      Directory of D:\
  162.  
  163.      123R23       <DIR>     12-01-91   2:45p
  164.      ARTICLES     <DIR>     04-12-92   6:54p
  165.      CSERVE       <DIR>     12-08-91   7:15p
  166.      EXCEL        <DIR>     07-05-91   6:17p
  167.      GMK          <DIR>     04-11-92   4:24p
  168.      JUNK         <DIR>     02-17-92   8:31p
  169.      TAP          <DIR>     03-21-92  11:50a
  170.      VB           <DIR>     07-13-91  10:45p
  171.      VISION       <DIR>     12-22-91   7:04p
  172.      VISIONR      <DIR>     12-22-91   7:25p
  173.      WP51         <DIR>     01-24-92   8:08p
  174.      WPC          <DIR>     03-29-92   5:47p
  175.      WPWIN        <DIR>     03-29-92   5:46p
  176.      WPWINDOC     <DIR>     03-29-92   5:46p
  177.      18 file(s)          0 bytes
  178.      18792448 bytes free
  179.  
  180.      There are a couple of interesting items about these subdirectory
  181.      listings.  Instead of showing a file size, subdirectories are
  182.      displayed with a "<DIR>."  This shows that these are directories,
  183.      not files without extensions.  You can see from the byte listing
  184.      at the bottom of the display that subdirectory "files" have a
  185.      zero-byte length.
  186.  
  187.      If you do a DIR command on a subdirectory, you'll see two special
  188.      <DIR> entries at the beginning of the listing:
  189.  
  190.      Volume in drive D is STACVOL_DSK
  191.      Directory of D:\ARTICLES
  192.  
  193.      .            <DIR>     04-12-92   6:54p
  194.      ..           <DIR>     04-12-92   6:54p
  195.      MEMHELP  BAK     19534 02-28-92   7:43p
  196.      DEFINEKY BAT      1159 03-04-91   6:17p
  197.      AUTOEXEC HLP     50345 08-20-91   8:44p
  198.      CACHE    HLP      6243 12-29-91  11:06a
  199.      PROFILE  KEJ      1361 01-26-92   7:48p
  200.      XNAME    LIB      4485 05-23-92   3:02p
  201.      CACHE    LOG      8687 12-22-91   7:54p
  202.      DOSBOOK  MST      5538 04-14-92   9:36p
  203.      DELERASE OUT     13017 01-25-92  10:05a
  204.  
  205.      The "." stands for the current directory, here D:\ARTICLES.  The
  206.      double periods ".." stand for the parent directory, the directory
  207.      that is immediately above this one.  In this example the parent
  208.      directory is the root directory (D:\).  You can use this ".."
  209.      shorthand to quickly move up one level in the directory tree, as
  210.      we'll see below.
  211.  
  212.  
  213.      Now let's look at the commands used to manage subdirectories and
  214.      files.
  215.  
  216.      MD (or MKDIR) -- create a new subdirectory
  217.  
  218.      The MD Command (no one uses the long version, MKDIR) will create
  219.      a new subdirectory.  The syntax is:
  220.  
  221.           MD [d:][path]dirname
  222.  
  223.      where "dirname" is the subdirectory name.  If you simply enter
  224.      the name, the subdirectory will be created below the directory
  225.      that you are currently in.  Alternatively, you can show exactly
  226.      where to create this directory by including drive and path
  227.      information.  For example, suppose you are in the C:\DOS
  228.      subdirectory.  The command
  229.  
  230.           MD UTILITY
  231.  
  232.      will create a C:\DOS\UTILITY subdirectory.  With no path given,
  233.      the new directory is created relative to the default directory.
  234.      The command
  235.  
  236.           MD \UTILITY
  237.  
  238.      will create a C:\UTILITY directory directly off the root, no
  239.      matter which subdirectory you are in on the C: drive when you
  240.      issue the command.
  241.  
  242.  
  243.      RD (or RMDIR) -- delete a directory
  244.  
  245.      To remove a subdirectory no longer needed, you can use the RD
  246.      command (again, no one uses the longer RMDIR version).  The
  247.      syntax is:
  248.  
  249.           RD [d:][path]dirname
  250.  
  251.      where "dirname" is the directory to remove.
  252.  
  253.      You cannot remove the root directory, or directory you are
  254.      currently in (the default directory).  A directory must be empty,
  255.      containing no files or subdirectories, before it can be removed.
  256.      A hidden file may prevent you from removing a directory, since
  257.      the file cannot be deleted with DEL or ERASE.  If you have DOS
  258.      5.0, you can use the ATTRIB command to turn off the Hidden
  259.      attribute, then delete the file normally.  If you don't have DOS
  260.      5.0, you'll have to use a third party utility such as PCTools or
  261.      Norton Utilities to unhide and delete such files.
  262.  
  263.  
  264.      CD (or CHDIR) -- changes the default directory
  265.  
  266.      The CD Change Directory command is used to move around the
  267.      directory tree.  The syntax is:
  268.  
  269.           CD [d:][path][dirname] [..] [\]
  270.  
  271.      where "dirname" is the name of the directory that you want to
  272.      move to.  If you simply give the directory name, then that
  273.      directory must be directly below the default directory.
  274.      Otherwise you will receive an "Invalid directory" message.  You
  275.      can move to any directory on the drive by explicitly giving the
  276.      path and directory name.
  277.  
  278.      Other uses of the CD command are:
  279.  
  280.           CD \      Will move you back to the root directory.
  281.  
  282.           CD ..     Will move you up one level to the "parent"
  283.                     directory of the directory you are currently in.
  284.                     You can also use this as shorthand to move to
  285.                     another directory with the same parent, as shown
  286.                     below.
  287.  
  288.           CD        Will show the name of the current directory.
  289.  
  290.      Let's look at some examples of the CD command.  Let's say that
  291.      our disk is organized like so and that you are in the ARTICLES
  292.      subdirectory under the WP51 subdirectory:
  293.  
  294.                               C:\ (ROOT)
  295.                  ┌─────────┬──────┴───────┬──────────┐
  296.               123R23      WP51           UTIL       DOS
  297.                  │         │              │
  298.             ┌────┴───┐    BIN           NORTON
  299.             │        │
  300.           MEMOS   ARTICLES  <-- you are here
  301.             │        │
  302.     ┌───────┴┐    ┌──┴─────┐
  303.     │        │    │        │
  304.   1991     1992  CCS     LAWMUG
  305.  
  306.  
  307.      CD ..          will move you up to the parent, here the WP51
  308.                     subdirectory (C:\WP51).
  309.  
  310.      CD \           will move you back to the root directory (C:\).
  311.  
  312.      CD CCS         will move you down to the CCS subdirectory
  313.                     (C:\WP51\ARTICLES\CCS).  Since there is no path
  314.                     specified, DOS looks for this subdirectory below
  315.                     the current directory.
  316.  
  317.      CD \UTIL\BIN   will move you to the BIN subdirectory
  318.                     (C:\UTIL\BIN).  Since the directory name starts
  319.                     with \, DOS begins looking for the UTIL
  320.                     subdirectory off the root.
  321.  
  322.      CD ..\MEMOS    will move you to the MEMOS subdirectory
  323.                     (C:\WP51\MEMOS).  You use the ".." as shorthand
  324.                     for the parent directory, here C:\WP51.  It is a
  325.                     quick way to move to another subdirectory with the
  326.                     same parent.
  327.  
  328.      CD             will simply display the current directory
  329.                     (C:\ARTICLES).
  330.  
  331.  
  332.      PROMPT -- change to DOS prompt to show the current subdirectory
  333.  
  334.      In a complicated directory structure it is easy to get lost.  You
  335.      can use the PROMPT command can end subdirectory confusion by
  336.      always displaying the name of the current directory.  You've seen
  337.      the default DOS prompt often, the infamous "C>".  The PROMPT
  338.      command can change "C>" to something a lot more informative.
  339.  
  340.      The syntax of the command is:
  341.  
  342.           PROMPT [prompt_text]
  343.  
  344.      where "prompt_text" is any string of text or special characters.
  345.      These special characters will display system information as part
  346.      of your prompt:
  347.  
  348.           $P   the default directory
  349.           $T   the current time (HH:MM:SS.xx)
  350.           $D   the current date (MM-DD-YY)
  351.           $V   the DOS version
  352.           $N   the default drive
  353.           $_   Carriage Return (moves the cursor to next line)
  354.           $G   the > character
  355.           $L   the < character
  356.           $B   the | character
  357.           $Q   the = character
  358.  
  359.      As you can see, the standard DOS prompt is $N$G, the default
  360.      drive and the ">" sign.  If you enter the PROMPT command with
  361.      nothing after it, DOS resets the prompt to this default.
  362.  
  363.      The prompt is usually set in your AUTOEXEC.BAT file, though it
  364.      can be reissued anytime from the DOS command line.  Perhaps the
  365.      most common prompt setting is the current drive and directory:
  366.  
  367.           PROMPT $P$G
  368.  
  369.      DOS will display the current drive and current directory, with
  370.      the greater than sign.  For example, if you are in the MEMOS
  371.      subdirectory of the WP51 directory on your C: drive, your prompt
  372.      will show:
  373.  
  374.           C:\WP51\MEMOS>_
  375.  
  376.      There is one minor problem when having DOS display the current
  377.      directory ($P).  Each time you press Enter, DOS reads the disk to
  378.      find the directory for the prompt.  If your default drive is a
  379.      floppy drive and you take the disk out (or you try to change to a
  380.      drive without a disk), DOS will try to read the empty drive and
  381.      you'll get an error message:
  382.  
  383.           Not ready reading drive A:
  384.           Abort, Retry, Fail?_
  385.  
  386.      At this point you can put a disk in and press R.  Or you can
  387.      simply press F, in which case your prompt will become:
  388.  
  389.           Current drive is no longer valid>_
  390.  
  391.      Just change back to your hard drive and your prompt will
  392.      reappear.
  393.  
  394.      By the way, there is an undocumented CONFIG.SYS setting in DOS
  395.      5.0 that will enter an "F" for you at any "Abort, Retry, Fail"
  396.      messages.  You do this by adding a "/F" switch to the
  397.      SHELL=COMMAND.COM statement in CONFIG.SYS.  Now anytime an
  398.      "Abort, Retry, Fail" message occurs, DOS will automatically
  399.      answer "Fail" and continue.  Note that this switch is used with
  400.      COMMAND.COM as your command processor, and most likely does not
  401.      apply if you are using another processor (such as Norton's NDOS).
  402.  
  403.  
  404.      PATH -- where to search for files
  405.  
  406.      The PATH command tells DOS the subdirectories to search when it
  407.      can't find the specified program in the current directory.  DOS
  408.      will search this "path" of directories before it returns the "Bad
  409.      Command or Filename" error message.  Some application programs
  410.      also use the path to find related files.
  411.  
  412.      The path is specified by listing the directory to search,
  413.      separated by semicolons:
  414.  
  415.           PATH dirname1;dirname2;dirname3; ....
  416.  
  417.      A typical path might look like this:
  418.  
  419.           PATH C:\;C:\DOS;C:\UTIL;C:\WINDOWS;C:\PCTOOLS;C:\DOS\NORTON
  420.  
  421.      This path tells DOS to look in the following places (in the order
  422.      listed) for the file specified, if it can't be found in the
  423.      current directory:
  424.  
  425.           C:\            (the root directory of the C: drive)
  426.           C:\DOS         (the DOS subdirectory on the C: drive)
  427.           C:\UTIL        (the UTIL subdirectory on the C: drive)
  428.           C:\WINDOWS     (the WINDOWS subdirectory on the C: drive)
  429.           C:\PCTOOLS     (the PCTOOLS subdirectory on the C: drive)
  430.           C:\DOS\NORTON  (the NORTON subdirectory in the DOS
  431.                          subdirectory on the C: drive)
  432.  
  433.      The PATH is normally set in the AUTOEXEC.BAT file, and is limited
  434.      to 127 characters in length (the limit of the DOS command line).
  435.      If you have only a single hard drive, you can save a few
  436.      characters by eliminating the "C:" drive identifier.  The path
  437.      above could be specified as:
  438.  
  439.           PATH \;\DOS;\UTIL;\WINDOWS;\PCTOOLS;\DOS\NORTON
  440.  
  441.      You'll want to put your important subdirectories on the path,
  442.      with the most "important" first, but don't include every
  443.      subdirectory.  Long paths mean that DOS must search each of the
  444.      listed subdirectories, including every time you make a typo or
  445.      spelling mistake.  Long paths can definitely slow you down,
  446.      particularly with a sluggish hard drive.
  447.  
  448.      There are a couple of ways of viewing the current path.  If you
  449.      simply enter "PATH" at the DOS prompt, DOS will display the path.
  450.      You can also enter the "SET" command to see the path, since DOS
  451.      keeps the path as an environmental variable.  The SET command
  452.      will show all the environmental variables, including the PATH,
  453.      PROMPT, and COMSPEC.  (See the January 1992 Hard-Copy Beginner's
  454.      Column for a discussion of the DOS Environment.)
  455.  
  456.      Since the path is an environmental variable, it can be accessed
  457.      and manipulated in a batch file.  This means you can dynamically
  458.      change the path as needed.  For example, I use Grammatik 5 as a
  459.      grammar checker, but don't have it on my PATH statement.  However
  460.      when I want to use Grammatik, the Grammatik subdirectory (\GMK)
  461.      must be on the path or the program can't run.  So I've set up a
  462.      batch file to put the \GMK subdirectory on the path, run
  463.      Grammatik with WordPerfect, then remove \GMK from the path:
  464.  
  465.      @echo off
  466.      set oldpath=%path%
  467.      path=d:\gmk;%path%
  468.      cd \wp51
  469.      gmkwp
  470.      path=%oldpath%
  471.      set oldpath=
  472.  
  473.      Let's take a closer look at this batch program.  The second line
  474.      creates a new environmental variable "oldpath" that contains the
  475.      original path (to use an environment variable in a batch file,
  476.      you surround it with percent signs).  The next line creates a new
  477.      path, with the "D:\GMK" subdirectory as the first directory
  478.      listed; in essence, the original path is tacked on the end of
  479.      \GMK.  The 4th and 5th lines change to the WordPerfect
  480.      subdirectory and run the Grammatik program.  When Grammatik is
  481.      done, the 6th line sets the path back to the original path, which
  482.      was stored in the "oldpath" variable.  The final line removes the
  483.      "oldpath" variable from the environment, freeing up the memory it
  484.      occupied.
  485.  
  486.