home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / DOS_HELP / PCLEARN.ZIP / BATCH.TUT < prev    next >
Encoding:
Text File  |  1988-12-13  |  9.0 KB  |  202 lines

  1.  
  2. -------------------------------------------------------------------------
  3.  BATCH FILES FOR EFFICIENCY - GETTING THE WORK DONE
  4. -------------------------------------------------------------------------
  5.  
  6. A batch file is little more than a series of DOS commands placed into
  7. a separate file. The commands are simply a list of operations you wish the 
  8. computer to perform. These operations can be DOS operations (e.g., 
  9. format a disc, display the date and time, etc) or other operations which
  10. load or start another program.  Each line of a batch file contains one
  11. instruction or operation for the computer to perform. Don't worry about
  12. understanding the following example, just note that each instruction is
  13. on a separate line . . .  
  14.  
  15. example:
  16.  
  17.  rem this is the start        (a remark displayed on screen)
  18.  date                         (date displayed)
  19.  time                         (time displayed)
  20.  ver                          (DOS version displayed)
  21.  dir a:/p                     (directory of a: displayed)
  22.  rem now let's load 123       (another remark)
  23.  123                          (start program named 123)
  24.  rem end of batch file        (final remark)              
  25.  
  26.  
  27. The primary use of batch files and commands is to automate sequences 
  28. or instructions which you might use frequently. A batch file always has 
  29. the extension BAT (example: autoexec.bat, hello.bat).
  30.  
  31. Each line in the batch file is a separate command and is performed 
  32. as if you had typed in the command from your keyboard at the DOS 
  33. prompt. In addition to the usual DOS commands, batch files can also 
  34. contain special commands which allow you to build small programs. 
  35. Branching (selecting various directions or choices) and iteration 
  36. (repititions of a command) are allowed within the framework of 
  37. these additional batch commands. In addition, batch files may 
  38. have special parameters or inputs passed to them at the time 
  39. you cause the batch file to execute.
  40.  
  41. A batch file is started by typing the file name without the extension.
  42.  
  43. Example: a>hello  (starts the file hello.bat)
  44. Example: c>whoops  (starts the file whoops.bat) 
  45.   
  46. The autoexec.bat file is a special batch file which is usually placed in 
  47. the main or root directory of a disk and automatically executes a series 
  48. of commands (which you have placed there) every time you start the 
  49. computer. In effect, the autoexec.bat file customizes the starting
  50. sequence of the computer to your liking.
  51.  
  52. To terminate or stop any batch file in progress (including autoexec.bat)
  53. issue the break command (control-break  OR   control-scroll lock).
  54.  
  55. Let's prepare a batch file:
  56.  
  57. First make sure you have a formatted disc in your disc drive and DOS
  58. is operating normally and displays a DOS prompt.
  59.  
  60. Type following list with a DOS prompt such as a>
  61.  
  62. Example:
  63.  
  64. copy con 1.bat         (press enter)   (cursor skips to new line)
  65. rem Hello there        (press enter)
  66. ver                    (press enter)
  67. date                   (press enter)
  68. dir/p                  (press enter)
  69. ^Z                     (press F6 OR hold control AND Z, then press enter)
  70.  
  71. When done you'll have prepared a batch file of dos commands
  72. named 1.bat. This small file will print hello there then type the
  73. DOS version in use then display date and finally produce a directory 
  74. listing and pause after each screenful.
  75.  
  76. To get the batch file to execute or operate,just type  1  (enter)
  77.  
  78. Another example:
  79.  
  80. copy con f.bat          (press enter)
  81. cls                     (press enter)
  82. format b:/s             (press enter)
  83. rem all done            (press enter)
  84. ^Z  (press F6) then     (press enter)       
  85.                                                     
  86.  
  87. This batch file (activated by typing f then enter) will clear
  88. the screen then prepare to format a blank disc in b: drive - you
  89. must have the format file on the same disc as this batch file - 
  90. remember that format is an EXTERNAL command. After the batch
  91. file has formatted the disc it prints "all done" on the screen. 
  92.  
  93. One batch file and start or call another, but the original batch
  94. file cannot be returned to - you must continue on within the second
  95. batch file. If a batch file contains a typing or syntax error in any
  96. of its commands, the computer will stop execution at that point and
  97. return you to DOS.
  98.  
  99. Use your imagination and construct batch files to shorten your
  100. typing tasks. And for a pop quiz, examine the batch file(s)
  101. on this disc with pc-learn! (hint: use the type command to display
  102. file contents. example: type 1.bat).
  103.  
  104. -------------------------------------------------------------------------
  105. AUTOEXEC.BAT FILE BASICS - THE WAKEUP CALL TO YOUR COMPUTER
  106. -------------------------------------------------------------------------
  107.  
  108. The autoexec.bat file starts your computer exactly the way you want.
  109. It allows you to customize the initial "warmup" as the computer
  110. comes to life. You can cause the autoexec.bat file to print a
  111. startup menu of choices, load one particular program, execute
  112. another batch file and other useful tasks. The autoexec.bat 
  113. file is the FIRST file DOS runs after loading itself and starting the
  114. computer. The autoexec.bat file must been on the same disc as DOS
  115. when the computer starts.
  116.  
  117. An autoexec.bat file can always be modified later, enlarged, edited,
  118. revised or deleted as you wish. Sometimes it is useful to have several
  119. autoexec.bat files. Each on a different startup disc to operate different
  120. programs. An autoexec.bat file (like all bat or batch files) can be
  121. modified with any ascii (common) word processor. You don't have to
  122. use the copy con facility each time!
  123.  
  124. Example:
  125.  
  126. Prepare this file as you have prepare other batch files seen above.
  127.  
  128. First make sure you have a formatted disc in your disc drive and DOS
  129. is operating normally and displays a DOS prompt.
  130.  
  131. Type following list with a DOS prompt such as a>
  132.  
  133. copy con autoexec.bat                       (press enter)
  134. 123                                         (press enter)
  135. ^Z                (press F6 OR hold control AND Z, then press enter)
  136.          
  137. This means (first line) create a file named autoexec.bat as typed from the 
  138. keyboard or con (console). (next line) execute the program named 123. (next 
  139. line) end of my orders from the keyboard - prepare the file and stash it on 
  140. the disc. When finished you'll see a file named autoexec.bat on your
  141. directory listing screen which contains automatic startup instructions.
  142. You can also startup the autoexec.bat by typing autoexec and then pressing
  143. enter. To take a "peek" at the contents of an autoexec.bat file (or any
  144. bat file) simply use the type command. Example: c>type autoexec.bat
  145. Example: a>type b:autoexec.bat
  146.  
  147. Here is another autoexec.bat file, this time from a hard drive startup
  148. sequence; it provides a higher degree of control and specific
  149. direction that a computer user might need for hard drive customization 
  150. and more versatle use:
  151.  
  152. copy con autoexec.bat                             (press enter)
  153. path \dos;\reflex;\wp;\util;\doc;\nor;\bat        (press enter)
  154. prompt $P$G                                       (press enter)
  155. cpu n                                             (press enter)
  156. verify on                                         (press enter)
  157. blank                                             (press enter)
  158. mode bw80,r                                       (press enter)
  159. dispclk                                           (press enter)
  160. type menu                                         (press enter)
  161. ^Z           (press F6 OR hold control AND Z, then press enter)
  162.  
  163.  
  164. Let's examine this more complicated autoexec.bat file in greater detail:
  165.  
  166. The first line establishes a path command to help DOS search every
  167. subdirectory on the hard disc (you don't have to switch around to
  168. different areas of the disc - DOS will search around for you since
  169. it now know the various "paths" to take.)
  170.  
  171. The second line alters the cursor prompt to tell you your location 
  172. and subdirectory. 
  173.  
  174. The third line is a reference to the speed the computer will operate at
  175. and is a unique command to a particular brand of machine (cpu n means
  176. start the central processing unit chip at normal speed.)
  177.  
  178. The fourth line turns on the verify function for file copying.
  179.  
  180. The next line instructs the DOS mode function to switch to black and
  181. white display, 80 columns wide and shift one colummn to the right for
  182. alignment.
  183.  
  184. Next we ask DOS to tell us the time and date.
  185.   
  186. A final line instructs DOS to type to the screen a file containing
  187. the menu for this disc.
  188.  
  189. The ^Z of course ends the file and instructs DOS to store the file
  190. away for future use on the disc.
  191.  
  192. Try preparing small (or large) autoexec.bat files and see what they
  193. do. One clever idea is to store unused files by renaming them temporarily
  194. (with the DOS ren command) Example: a>ren autoexec.bat auto1.bat. Now you can 
  195. create another autoexect.bat file while leaving the primary file undisturbed.
  196. You can always go back and rename the primary file autoexec.bat in case
  197. you have problems and need to retrieve it.
  198.  
  199.  
  200. end of article, now press escape key to return to menu
  201.  
  202.