home *** CD-ROM | disk | FTP | other *** search
/ 8+1 Entertainment Pack: Game Pack 2 / VOL02.bin / hotkeys / hotkey4 / what_box / batch.txt < prev    next >
Encoding:
Text File  |  1993-11-26  |  5.2 KB  |  172 lines

  1.                  BATCH FILES
  2.  
  3.     Batch files are files with a .BAT
  4. extension which have a special function with
  5. DOS.  They contain one or more lines of text
  6. which are the same as commands you can type
  7. at the command line.  When you type the name
  8. of a batch file at the command line, it's
  9. lines are executed by DOS just as if you
  10. typed them at the command line yourself.
  11.  
  12.    A simple use of a batch file is to replace
  13. a long typing job at the command line with a
  14. short one.  Let's say you want to start a
  15. program called STARGAME.EXE which happens to
  16. be in a sub-directory called
  17. D:\GAMES\MYGAMES\STARGAME. Normally you would
  18. have to type:
  19.  
  20. D:\GAMES\MYGAMES\STARGAME\STARGAME.EXE
  21.  
  22.     Instead, you can create a batch file
  23. with any text editor or word processor which
  24. works in standard ASCII text mode and call it
  25. SG.BAT. SG.BAT can contain a single line of
  26. text: D:\GAMES\MYGAMES\STARGAME\STARGAME.EXE.
  27.  
  28. Now, to start STARGAME all you have to do is
  29. type SG.
  30.  
  31.    Going a step further, let's say that you
  32. have to switch to the sub-directory
  33. containing STARGAME before you can run it,
  34. because the game itself needs to access files
  35. in it's directory.  And, perhaps you are
  36. logged to a different disk.  Normally you
  37. would have to type three lines before you
  38. could play the game:
  39.  
  40. D:
  41. CD \GAMES\MYGAMES\STARGAME
  42. STARGAME
  43.  
  44. If you wrap these three lines up in a batch
  45. file called SG, then you'll only have to type
  46. SG to start your game.
  47.  
  48.     Many programs come with their own batch
  49. files to make your life easier.  Instead of
  50. having to look over a long list of files
  51. which come with the main program, you can
  52. just look for a start-up batch file.  Common
  53. batch file names are BEGIN.BAT, GO.BAT and
  54. START.BAT.  Other likely names are the same
  55. name as the program, or the initials of the
  56. program, followed by .BAT.
  57.     If you have a program which comes with a
  58. start-up batch file, it is best to use it,
  59. rather than running the program directly,
  60. because start-up batch files may contain
  61. auxiliary information which your program
  62. needs to start properly.  For instance, it
  63. may run differently depending on whether it
  64. is installed on a hard disk or floppy disk.
  65. The proper way to start will be contained in
  66. the batch file.
  67.  
  68.     Batch files can run most DOS commands
  69. including COPY, DIR, DEL, and CD, RD and MD.
  70.     You can use combinations of these to
  71. accomplish tasks you do often.
  72.     It is common to use MD to create a
  73. directory, then immediately switch to that
  74. directory.  I've made myself a little batch
  75. file called ZD.BAT.  It contains:
  76.  
  77. MD \%1
  78. CD \%1
  79.  
  80. %1 represents a variable, it is whatever you
  81. type on the command line after the batch file
  82. name. In this case, it is a new directory
  83. name. So, if I wanted a new directory called
  84. \FROG, I could simply type:
  85.  
  86. ZD FROG
  87.  
  88. and my new directory will be created.
  89. (Notice I don't even have to type the
  90. backslash, since the batch file does that for
  91. me.
  92.  
  93.     In addition to using the %1 variable,
  94. there are 8 more, %2 through %9, each one
  95. will pick up the next successive word,
  96. filename or directory name you type at the
  97. command line.  If you were to create a batch
  98. file containing these lines:
  99.  
  100. COPY %1 A:
  101. COPY %2 A:
  102. COPY %3 A:
  103.  
  104. Then you could type the batch file name,
  105. followed by three filenames (separated by
  106. spaces) and they would all be copied to a
  107. floppy disk in the A drive.
  108.  
  109.      There is also a %0, which refers to the
  110. batch file itself.  You can use it for such
  111. operations as making a self-deleting batch
  112. file.  A batch file for installing a new
  113. program is useful only once, so you can add
  114. the line:
  115.  
  116. DEL %0
  117.  
  118. to the end of the batch file, and it will
  119. disappear when it is done installing the
  120. program.
  121.  
  122.     Echo is a DOS command which will show
  123. whatever follows.  So a batch file containing
  124. this line:
  125.  
  126. ECHO Hello there!
  127.  
  128. would display "Hello there!" when run.
  129.  
  130. In a batch file containing other commands,
  131. your ECHO messages may not stay on the screen
  132. for very long, so you can use another DOS
  133. command called PAUSE, which will stop the
  134. batch file until the user presses any key.
  135.  
  136.     There is a DOS command called TYPE which
  137. will display up to a screenful of text at one
  138. time from any standard ASCII file.  You can
  139. use this in batch files to display important
  140. information.  Example:
  141.  
  142. TYPE README.DOC
  143.  
  144.                 AUTOEXEC.BAT
  145.  
  146.     There is a special batch file in the root
  147. directory of your hard disk called
  148. AUTOEXEC.BAT.  When the computer is turned
  149. on, and DOS is loaded, it looks for this
  150. batch file.  If found, it processes what it
  151. finds in AUTOEXEC.BAT right away.  It is
  152. common for computers with Microsoft Windows
  153. installed to have an AUTOEXEC.BAT file
  154. containing the line WIN, to automatically
  155. start Windows everytime the computer is
  156. turned on.
  157.  
  158.     These basics will help you get started
  159. with batch files.  There is much more to
  160. batch files, and whole books have been
  161. written about batch language programming.
  162. Special programs have also been written to
  163. extend the powers of batch files into
  164. processing math, asking for and processing
  165. user input, and displaying graphics.
  166.  
  167. _____________________________________________
  168.                               end of file.
  169.  
  170.  
  171.  
  172.