home *** CD-ROM | disk | FTP | other *** search
/ The CIA World Factbook 1992 / k3bimage.iso / sel / 04 / 0040 / hdtricks.txt < prev    next >
Encoding:
Text File  |  1991-12-02  |  11.3 KB  |  239 lines

  1.                        I. HARD DISK ORGANIZATION
  2.               AND SOME NEAT THINGS TO DO WITH BATCH FILES
  3.  
  4.  
  5.  
  6.         This article assumes some familiarity with subdirectories and
  7.    paths.  Subdirectory names are given in uppercase, to distinguish
  8.    them from file names.  "Cd" is the DOS command to change directory.
  9.  
  10.  
  11.    OVERALL ORGANIZATION:
  12.  
  13.         Large applications which contain many program files, such as
  14.    databases, word processors, spreadsheets, etc. should each be in
  15.    their own "first-level" subdirectory (ie. at root level).  The data
  16.    files they use may be in "second-level" subdirectories under the
  17.    application subdirectory, or in "first-level" subdirectories.  I
  18.    prefer the former.
  19.  
  20.         A good hard disk organization should look something like this
  21.    hypothetical one, with the subdirectories on the left being at root
  22.    level and the ones indented under them at second level:
  23.  
  24.              \BASIC
  25.              \BAT
  26.              \DBASE
  27.                   \DBASE\INVENTORY
  28.                   \DBASE\VIDEO
  29.                   \DBASE\BOOKS
  30.              \DOS
  31.              \LOTUS
  32.                   \LOTUS\FINANCE
  33.                   \LOTUS\MISC
  34.              \WORD
  35.                   \WORD\LETTERS
  36.                   \WORD\MISC
  37.              Ibmbio.com (invisible)
  38.              Ibmdos.com (invisible)
  39.              ansi.sys
  40.              autoexec.bat
  41.              command.com
  42.              config.sys
  43.  
  44.         I don't use many BASIC programs, so I keep them all in the same
  45.    subdirectory as the language program, since there is only one
  46.    language file in gwbasic (and two in IBM BASIC, I believe).
  47.  
  48.         In addition to the subdirectories, the root should contain only
  49.    a few necessary files, basically the ones shown above, and possibly
  50.    others that some applications may require there.  For convenience,
  51.    and to prove I am not a fanatic, I throw a few miscellaneous files in
  52.    the root: rdclk.com and stclk.com (for my battery-operated clock-
  53.    calendar), and sit.com (for parking my hard disk).  Ansi.sys and
  54.    vdisk.sys (if a ram disk is to be used) can be placed in the
  55.    subdirectory \DOS if config.sys contains the lines:
  56.                   device = c:\DOS\ansi.sys
  57.                   device = c:\DOS\vdisk.sys
  58.  
  59.  
  60.    THE AUTOEXEC.BAT FILE:
  61.  
  62.         A special file which must be named autoexec.bat can be put in
  63.    the root, and will do certain things each time the hard disk is
  64.    booted, such as set the time and date if a clock-calendar is
  65.    installed, and set a path.  The file should be something like this:
  66.                   break = on
  67.                   prompt = $p $q$g
  68.                   path = c:\; c:\DOS; c:\BAT
  69.                   cls
  70.                   rdclk
  71.  
  72.         I like to use the prompt line given, to modify the DOS prompt to
  73.    display the path to the current subdirectory ($p), an equal sign
  74.    ($q), and the normal "greater-than" sign ($g), so it looks like this:
  75.                   C:\ =>
  76.                   C:\BASIC =>
  77.                   C:\WORD\MISC =>
  78.  
  79.  
  80.    THE PATH STATEMENT:
  81.  
  82.         The DOS subdirectory is included in the path so DOS commands can
  83.    be issued from any subdirectory.  Putting the BAT subdirectory in the
  84.    path allows a neat bit of trickery, detailed below. The path may need
  85.    to be augmented with other subdirectories for certain special
  86.    applications, but there is no reason to put all of them there.
  87.  
  88.  
  89.    THE BATCH FILE SUBDIRECTORY:
  90.  
  91.         Let's say you want to start Lotus.  If its subdirectory is not
  92.    in the path, you would normally have to type "cd\lotus" then "lotus".
  93.    But there is a better way.  If applications are accessed by batch
  94.    files which are all in a subdirectory in the path, you can start any
  95.    application from any subdirectory.  The BAT subdirectory takes the
  96.    place of putting all the subdirectories in the path.
  97.  
  98.         I like to give each batch file the name of the command to start
  99.    the application (but the extension is .bat).  Each one contains, at
  100.    least, commands to do the appropriate cd and start the application:
  101.                   lotus.bat:
  102.                      cd \LOTUS
  103.                      lotus
  104.  
  105.         When you type a command at the DOS prompt, the computer will
  106.    look for a .com or .exe file of that name, or (failing that) .bat, in
  107.    the logged subdirectory, and if it doesn't find it there, in the
  108.    subdirectories in the path.  (One caution -- if you are already in
  109.    the application subdirectory, and the batch file has the same name as
  110.    the application's starting command, the batch file won't be found --
  111.    the .com or .exe file in the current subdirectory will.)
  112.  
  113.         This \BAT system is a sort of "transparent" menu system.  With
  114.    this organization, any application can be started from any
  115.    subdirectory (at any level) merely by typing its name (the name of
  116.    the appropriate batch file) at the DOS prompt.
  117.  
  118.         You can also put other useful commands in these batch files.
  119.    For instance, in some applications you may wish to include commands
  120.    to set the printer to other than its usual configuration and reset it
  121.    after the application has run, to turn a screensaver off for an
  122.    application then back on again, etc.  After the application quits
  123.    control will return to the batch file and pick up any commands after
  124.    the call to the application.  I also include in \BAT several files
  125.    which are stand-alone printer commands, to let me easily set some
  126.    feature of my printer when I am not in an application that lets me do
  127.    it, such as indenting the left margin before I "type" a file to the
  128.    printer from DOS.  For more information on printer commands, see the
  129.    accompanying article "Printer Commands From Batch Files".
  130.  
  131.         A menu of these "application batch files" can even be made (as
  132.    another batch file), and started on each boot by putting its name as
  133.    the last item in the autoexec.bat file.  It can loop so that whenever
  134.    an application finishes, the menu is displayed again.  If this is
  135.    done, one of its options should be to exit to DOS.
  136.  
  137.  
  138.    A SPECIAL TRICK FOR RUNNING BASIC PROGRAMS:
  139.  
  140.         You can write a batch file to run a BASIC program so you don't
  141.    have to enter and exit BASIC manually. To start gwbasic and run a
  142.    BASIC program named filename.bas (assuming both are in the \BASIC
  143.    subdirectory):
  144.                   filename.bat:
  145.                      \BASIC\gwbasic \BASIC\filename
  146.    (You real IBM users substitute basica.)  The BASIC program should end
  147.    with "SYSTEM", to dump you right back to DOS where you were.  By
  148.    including the path(s), no matter what subdirectory you called it
  149.    from, the computer can find both gwbasic and the program to run.
  150.  
  151.  
  152.                        II. WRITING BATCH FILES
  153.                         
  154.  
  155.  
  156.         A batch file is just a "list" of DOS commands, executed in the
  157.    order given.  It is an ASCII text file with the extension .bat.  Some
  158.    of the DOS commands are useful only in batch files, and constitute
  159.    what is essentially a simple programming language built into DOS.
  160.    You run a batch file by typing its name, without the extension, from
  161.    the DOS prompt.
  162.  
  163.         You can write batch files in three ways: from the DOS prompt
  164.    using the "copy con filename.ext" command ("copy from the console"),
  165.    in EDLIN, or using a text editor.  EDLIN is a line-oriented editor
  166.    built into DOS. It is primitive by the standards of full-screen
  167.    editors, and therefore not intuitive to use, but don't be daunted by
  168.    it -- you don't have to be an assembly jock to use it.  And it's
  169.    always there at the DOS prompt.
  170.  
  171.         To use "copy con", from the DOS prompt:
  172.              Type: copy con filename.bat
  173.              (use the name with which you want it saved)
  174.              The cursor drops to the next line
  175.              Type the line(s) desired
  176.              When each line is done hit Enter
  177.              On the last line type Ctrl-Z and Enter
  178.    This ends and saves your file, and you are now a DOS "power-user".
  179.  
  180.         To write a batch file using EDLIN, from the DOS prompt:
  181.              Type: edlin filename.ext
  182.              (use the name with which you want it saved)
  183.              You will get an * prompt
  184.              Type: I  (for insert)
  185.              You will get a 1:*
  186.              Type the line(s) desired
  187.              When the line is done hit Enter
  188.              You will get a 2:*
  189.              Type: Ctrl-Z and Enter
  190.              You get the * prompt again
  191.              Type: E  (to save the file and exit to DOS)
  192.  
  193.         To write a batch file from a text editor, do it as you would any
  194.    other document, but if you are using a full-fledged word processor,
  195.    be sure to save the file unformatted (ie. as an "ASCII file").
  196.  
  197.  
  198.    SPECIAL BATCH FILES WITH NON-KEYBOARD CHARACTERS:
  199.  
  200.         Some batch files, especially those which contain printer
  201.    commands, may contain non-keyboard ASCII characters.  These
  202.    characters have to be entered in a special way.  For all of the
  203.    characters except ESC, it is done in all three of the above methods
  204.    (although not all text editors have this feature) by holding down the
  205.    Alt key while you type the character's ASCII code number (one to
  206.    three digits) on the numeric keypad.  (These are the numbers given in
  207.    the CHR$()'s in the BASIC version of a command.)  When you release
  208.    Alt a funny symbol will appear at the cursor, a different one for
  209.    each code.  The symbols for some codes are the regular alphanumeric
  210.    and punctuation characters you can type on the keyboard (ASCII codes
  211.    32-127), and for these you can just type the character.  If there is
  212.    any doubt whether you have the right character, do the Alt-number to
  213.    be safe.  Either way gives the same result in the file.  Don't hit a
  214.    spacebar between different codes, don't use the numbers above the
  215.    main keyboard, and you don't need Num Lock on.
  216.  
  217.         There is no way to enter the escape character using "copy con",
  218.    although you can enter a "dummy" character, then go into DEBUG or a
  219.    similar utility and substitute the hex code for ESC for that of the
  220.    dummy character.  The ESC character can be entered in EDLIN by a
  221.    control-V followed by a left square bracket.  As far as I know, all
  222.    of the text editors which allow the alt-number technique allow ESC to
  223.    be entered just like any other character, as alt-27.
  224.  
  225.         For the printer control batch files discussed in the article
  226.    "Sending Printer Commands From DOS", it is sometimes desirable to
  227.    avoid carriage return and line feed characters at the end of the
  228.    file.  You can do this in "copy con" by hitting Ctrl-Z at the end of
  229.    the line, not on a new line.  But this won't avoid a LF in an "echo"
  230.    file; it is useful only in a "codes-only" file used by a "type"
  231.    command, and you can't easily do most of those from "copy con", since
  232.    it is not easy to put in the ESC character.  As far as I know, you
  233.    can't avoid them in EDLIN, but you can delete them from the file with
  234.    at least some text editors, or DEBUG or one of the utilities that
  235.    lets you look at and modify a file in hex.  The CR is 0D and the LF
  236.    is 0A in hex.  (These are two of the characters given in an ASCII
  237.    table.)  You can avoid them in a text editor if you leave the cursor
  238.    on the line right after the last character.
  239.