home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / educatio / dosguide.zip / 16.DOC < prev    next >
Text File  |  1992-04-02  |  6KB  |  177 lines

  1.  
  2. .BAT (Batch Files)
  3.  
  4.  
  5.       PURPOSE:
  6.               Batch files combine a certain sequence of commands
  7.               and the entire sequence of commands is run simply
  8.               by typing the name of the batch file.
  9.  
  10.  
  11.       NOTE:
  12.            Batch files are very useful if you find that you are
  13.            repeatedly typing the same sequence of commands in
  14.            hopes of performing a common task.  Also note that
  15.            all batch files must include the ".bat" extension in
  16.            their filenames (example: message.bat).  By using
  17.            batch files you only have to remember to type one
  18.            command, the name of the specific batch file, instead
  19.            of several.
  20.  
  21.  
  22.       CREATING BATCH FILES:
  23.                            You can create a batch file using
  24.                            Edlin (the MS-DOS line editor) or
  25.                            any other line editor (such as Q),
  26.                            by using the "copy" command, or by
  27.                            using a word processor that saves
  28.                            files as ASCII text.
  29.  
  30.  
  31.       IMPORTANT:
  32.                 1) You must name each batch file with an extension
  33.                    of .bat
  34.  
  35.                 2) When you want to execute a batch file, you type
  36.                    only its filename and not the extension.
  37.  
  38.                 3) You can specify the name of another batch file
  39.                    as the last command in a batch file.  When you
  40.                    do this, you are able to call one batch file
  41.                    from another when the first has finished.
  42.  
  43.                 4) Setting the directory or drive affects every
  44.                    subsequent command in the batch file.
  45.  
  46.                 5) If you remove the disk that contains a batch
  47.                    file being run, DOS prompts you to reinsert
  48.                    the disk in order to continue following the
  49.                    commands in the file.
  50.  
  51.  
  52. COMMANDS USED IN BATCH FILES:
  53.  
  54.         COMMAND:       USAGE:
  55.  
  56.         cls            Clears the screen
  57.  
  58.         echo off       Used so commands in batch file are not
  59.                        echoed to the screen and cluttering up
  60.                        what you really want to say.
  61.  
  62.         echo           Everything typed after the word "echo"
  63.                        appears on the screen excluding the
  64.                        word "echo" when the batchfile is run.
  65.  
  66.         pause          Pauses during the process of a batch file
  67.  
  68.         rem            Displays a comment or remark in the batch
  69.                        file, but doesn't show up on the screen
  70.                        when the batch file is executed
  71.  
  72.         dir            Displays the default directory of the disk
  73.                        in the default drive
  74.  
  75.         date           Asks you to set the date (used mainly in
  76.                        autoexec.bat)
  77.  
  78.         time           Asks you to set the current time (used mainly
  79.                        in autoexec.bat)
  80.  
  81.         call           Calls one batch file from another without
  82.                        ending itself
  83.  
  84.       MORE SOPHISTICATED COMMANDS
  85.  
  86.                  COMMAND         USAGE
  87.  
  88.                   for            Performs a command for a set of files
  89.  
  90.                   goto           Processes commands starting with the line 
  91.                                  after the specified label
  92.  
  93.                   if             Performs a command if a condition is met
  94.  
  95.  
  96.       EXAMPLE:
  97.               The following is a sample batch file created through
  98.               the use of the "copy" command.  Through this batch
  99.               file you want to format and check new disks.  To do
  100.               this, follow these easy steps:
  101.  
  102.               1) First type the following command:
  103.  
  104.                    copy con mydir.bat
  105.  
  106.                  Then hit the ENTER key.  This command tells DOS to
  107.                  copy the information from the keyboard (console)
  108.                  to the file mydir.bat
  109.  
  110.               2) Next, type the following lines, hitting the ENTER
  111.                  key after each one:
  112.  
  113.                    rem   This is a file to display
  114.                    rem   my directory and pause it.
  115.                    pause HIT THE ENTER Key When Ready
  116.                    dir *.*/W/P
  117.  
  118.               3) Then, after the last line, press the CONTROL key
  119.                  and Z at the same time to save the batch file.
  120.                  The message "1 file(s) copied to show that the
  121.                  file has been created.
  122.  
  123.               4) To execute or run the file, simply type:
  124.  
  125.                    mydir
  126.  
  127.  
  128. CREATING BATCH FILES WITH REPLACEABLE PARAMETERS
  129.  
  130.  
  131.       PURPOSE:
  132.               You may want to create a program and run it with
  133.               different sets of data.  These different sets of
  134.               data may be stored in various DOS files.  Through
  135.               DOS, you are able to create a batch file with
  136.               replaceable parameters where a parameter is a
  137.               common option that you define.  Named %0 through %9,
  138.               these parameters hold the places for the values
  139.               that you supply when you give the batch command.
  140.               These replaceable parameters are useful because
  141.               they make certain batch files easier to use and
  142.               more flexible.
  143.  
  144.  
  145.       EXAMPLE:
  146.               You could create a file that says Good morning
  147.               and issues instructions.
  148.  
  149.  
  150.                    1) First type the following and then hit the
  151.                       ENTER key:
  152.  
  153.                         copy con Myfile.bat
  154.  
  155.                    2) Then type the following lines:
  156.  
  157.                         echo off
  158.                         cls
  159.                         echo Good Morning %1
  160.                         echo Hope all is well today.
  161.                         echo/
  162.                         echo Please don't forget to
  163.                         echo pick up the laundry %1
  164.                         echo/
  165.                         echo Thanks %1
  166.                         pause
  167.  
  168.  
  169.                    3) Next, hit the CONTROL key and Z at the same
  170.                       time to save the batch file, and then hit
  171.                       ENTER.
  172.  
  173.                    TO RUN THE BAT FILE type:
  174.  
  175.                       myfile Doris
  176.  
  177.