Chapter 1 Introduction To Batch (Bat) Files Batch File commands are the most powerful and versatile of the DOS commands. Writing Batch Files is the best way to learn how to use the DOS commands. In the next lessons you will write many Batch Files. You'll have an opportunity to see these Batch files come alive with the Menus, Programs and color combinations. You'll experience a sense of power that you have over the computer. This is a real accomplishment to learn one of the most powerful and useful parts of DOS. You'll be one of the few persons who'll know how to write a Batch File, a Program and a Menu---and in color. HOW TO WRITE BATCH FILES BATCH (BAT) FILE Bat (short for Batch File) is not a DOS command, but a file that is created with the Copy Command. It has special powers given to it by DOS. Bat Files can instruct the computer (DOS)) to carry out commands. Batch File commands can make the computer (DOS) create Menu-Driven-Programs; automate many DOS functions; beep; blink; change colors; show you what's in a file; print a file, and perform many other functions. GETTING STARTED To do the Lessons from this disk or from the Manual, you must first format a disk with the System files so it will start your computer. FORMATTING A DISK If you have only one disk drive, type the following next to the A> prompt: Format A:/S The computer will instruct you on what to do. If you have two disk drives, insert your DOS disk into drive A. Insert a Blank disk into drive B:. Now type the following next to the A prompt: Format B:/S When formatting is complete remove both disks. Insert your formatted disk (from drive B>) into the A> drive. THE COPY COMMAND The most versatile DOS command is the Copy command. With the Copy command all sorts of Batch Files can be created. The Batch Files being a special DOS file can give the computer all sorts of commands -3- from copying a file to formatting a disk. In this lesson the interest is in writing Batch Files, Programs and Menus. All of which the Batch File does very well. You'll first write a simple Batch File that will tell the computer to show you all the files (contents) of the directory of the disk in drive A. Check to see that your formatted disk is in the A> disk drive. WRITING THE FIRST BATCH FILE With your formatted disk in the disk drive, type the following next to the A:\> Prompt, like this: Copy Con First.Bat A: Dir Press F6 key, ------------- THE BAT FILE ABOVE TELLS US: ß That the first line contains the Copy command and the name of the Bat file (First). ß The next word after Copy is "Con" which stands for CONsole (keyboard). Con instructs the Copy command to copy from the keyboard what you are about to write. ß The second line "A:" stands for the A drive. This tells the computer that you are working with the disk in the A drive. ß The third line tells the computer that you wish to see on the screen the contents of the directory that is on the disk in the A drive. ß Line four is the Function key F6 (large key on top row) that tells the computer (DOS) that you are finished writing the Batch File. All that is left now is to strike the Enter key. The Batch file will be saved on the disk in the A> drive.  Now you will write four Batch files that will be used to change the screen color (Background) to Blue or Red and the letters to White or Yellow. You'll then display the files in the A: directory. WRITING THE FIRST COLOR BATCH-FILE (BB.Bat) (BB.Bat.. Blue Screen...also called Background) Type the following next to the A:\> Prompt, like sa this: Copy Con BB.Bat BB.Bat Dir Press F6 key, then press Enter key. ------------- WRITING THE SECOND COLOR BATCH-FILE (W.Bat) (W.Bat..White letters... also called Foreground) -4- Type the following next to the A> Prompt, like this: Copy Con W.Bat W.Bat Dir Press F6 key, then press Enter key. ------------- WRITING THE THIRD COLOR BATCH-FILE (Y.Bat) (Y.Bat.. Yellow letters) Type the following next to the A> Prompt. like this: Copy Con Y.Bat Y.Bat Dir Press F6 key, then press Enter key. ------------- WRITING THE FOURTH COLOR BATCH-FILE (RB.Bat) (RB.Bat.. Red background) Copy Con RB.Bat RB.Bat Dir Press F6 key, then press Enter key. ------------- We'll now go to Chapter 2 and see the Color Codes for the 8 foreground and 8 background colors. (8 X 8 =64 possible color combinations) -5- CHAPTER 2 INTRODUCTION TO COLOR CODES Two Easy Steps To A World Of Color Having a color monitor takes advantage of the color codes provided by the MS-DOS disk. These simple-to-learn codes will spark life into programs that you write and provide as many as 64 color combinations "free," just by typing a few short color codes. In the next sections, you will be creating color combinations and Menus that will contain Speed Keys. When creating these Menus you will also be adding a different color combination to each one. WHAT YOU WILL LEARN IN THIS CHAPTER Ansi Escape Codes For Color How To Use These Codes HOW TO GET STARTED WITH COLOR STEP 1. You must copy from the MS-DOS disk a file called Ansi.Sys. This file takes your color codes and adapts them so that your color monitor can use them. The next step is to store Ansi.Sys in a special file called Config.Sys so that it will be available to DOS when the computer is turned on. STEP 2. The Ansi.Sys file must be stored in the Config.Sys file as outlined on the next page. With this accomplished you will have the necessary components to run the color codes and have color appear on your color monitor. You start by copying the Ansi.Sys file from the DOS disk as follows: Insert the MS-DOS into the Computer. Next to the A> Prompt, type the following: Copy Ansi.Sys B: Follow the DOS prompts. Insert your disk when requested. A copy of the Ansi.Sys file from MS-DOS disk will be transferred to your disk. One More Step Leave your disk in the computer. In this next step, you are going to create a Config.Sys file in which you will put your Ansi.Sys command. To do this: type the following next to the A> Prompt, like this: Copy Con Config.Sys Device=Ansi.Sys F6 ------------ That's all there's to it! You now have the two files you need to get color. -6- The ANSI Color Escape Sequences The word ANSI stands for the "American National Standards Institute" which developed these codes. Below is a copy of the color Escape codes for setting color to the background and letters. These codes are called the ANSI Escape Codes, or Sequences for setting the foreground (letters or text) and background colors. Type as indicated. Don't use capital letters for the code.The Escape Code always starts: With a Dollar Sign ($) A Small (e) A Left Bracket ([ ) And ends with the small letter (m) All of the above parameters are used on the next page. SPECIAL ATTRIBUTE COMMANDS $e[0m Normal, white on black $e[1m Bold, high intensity $e[4m Underline if available $e[5m Blink $e[7m Reverse video These five commands are called attribute commands. They let you control the brightness, blinking and reverse video. THE COLOR CODES $e[30m black letters $e[40m black background $e[31m red letters $e[41m red background $e[32m green letters $e[42m green background $e[33m yellow letters $e[43m yellow background $e[34m blue letters $e[44m blue background $e[35m magenta letters $e[45m magenta background $e[36m cyan letters $e[46m cyan background $e[37m white letters $e[47m white background The group of Ansi codes list 8 colors for the letters and 8 colors for the background. Simple math shows that 8 x 8 =64. Therefore, we have 64 possible color combinations. HOW TO USE THESE COLOR CODES There are a few simple rules you must follow if you want the color codes to work: ß You must always start with the word "Prompt". ß Then the dollar sign, as the first entry after Prompt. ß Then the small e (Yes, you can use a capital E here.) ß Then the left bracket. ß End with a small m. (small m, please) ß Escape sequences may be combined by putting a semicolon after each item. YOUR FIRST ENTRY WILL BE TO CHANGE THE Screen Color to Black and White. -7- To do this, type the following next to the A> Prompt, like this: Prompt $e[0m $p$g The $e[0m is the code to reverse all colors to black and white. This is known as reverse video. Your screen will remain black and white until you add some of your own color or use a commercial program that has its own color program, or restart your computer. You should now have your original black and white colors on your screen. If you still have color on your screen, recheck the way you entered the Ansi Escape codes. It is important that you type the codes exactly as shown. Make certain that: ß The first word is "Prompt. Prompt ß The second word is the dollar sign ($). Prompt $ ß The third word is the small (e). Prompt $e ß The next, the left bracket ( [ ) Prompt $e[ ß Then the code number Prompt $e[7m ß Finally,next to the code type $p$g Prompt $e[7m $p$g The $p$g gives you this subdirectory prompt A:\>. When you type Escape codes and can't get any color change on the screen, you must restart (boot) your computer to enter these new escape commands into the computer's "memory." Press Esc key to return to Menu GO TO CHAPTER 3 "Color Combinations" -8- CHAPTER 3 COLOR COMBINATIONS In This Chapter You Will Learn: To Write 64 color combinations Experiment with 1 and 2-letter color codes Create A Color Menu WRITING YOUR OWN COLOR COMBINATIONS There are 8 colors that you will be using for the foreground (for letters) and eight for the background. This gives you 64 combinations from which to select your favorite colors. One approach to writing these codes is to use a simple formula for a set of 8 background colors and a set of 8 foreground (letters). This is easily done by using the first letter of each color: for example, R for red letters, and RB for red background. This code will also serve as the name of the Batch file. A SPEED COURSE IN INSTANT COLOR The Batch Files that you will be writing have been designed by the Author to change foreground or background color individually or together. The Batch Files that you write will contain the commands Echo Off and Clear Screen (Cls). Other information about the Batch File is described below. ß The Echo off command will prevent the codes from appearing on the screen. ß The Clear command will then clear the Echo Off command from the screen. ß When you enter a Letter command on the keyboard and press Enter, the Prompt and text will appear in that color. ß When you enter a Background command, the screen color will change. ß When you enter a letter (Y) and a background color (BB) the screen will show both color changes simultaneously. ß Each Batch File will contain a "Variable Parameter <%1>". This will make the Batch File accept another Batch File. This is how you can have the two colors change at the same time. ß The Directory command "DIR" will be included each Batch File. Since this is the last command in each Bat file it will provide text material to view with the color changes. Note the second item in each Batch file uses the variable %1. This is where the second Batch file is activated (executes). -9- For example, if you want yellow letters and blue background, the yellow letters execute first, then the blue background executes second from the variable %1. By using a variable you can substitute any color for %1. In the case above you could replace the blue background with any of the eight colors. The last item in each Bat file is the Directory command "DIR. This means whichever Batch file you use the program will always end with a display on the screen of the files in the directory. PUTTING COLOR CODES INTO A MENU Another way to check color is to put the list of color codes into a 2-letter Menu. Each time you make a color selection, you can return to the Menu by entering 2L. This will give you some color to look at while making your next selection. HOW TO WRITE THE 2L MENU APPEARS BELOW. The Menu is Written Like This: Type next to the A> prompt the following, like this: Copy Con 2L.Bat Prompt $p$g Echo off Cls Echo:====== 1 and 2-Letter Color Codes ====== Echo: Echo: Select 1 color from either column, or 2 colors, Echo: 1 for Letters and 1 for Background Echo: Then Press Enter Key Echo: Echo: R...Red letters RB... Red background Echo: G...Green letters GB...Green background Echo: Y...Yellow letters YB..Yellow background Echo: Echo: B...Blue letters BB...Blue background Echo: M...Magenta letters MB.Magenta background Echo: CY..Cyan letters CB...Cyan background Echo: Echo: W...White letters WB...White background Echo: BLK..Black letters BLB..Black background Echo:============================ Press F6 key, then press Enter key to finish Batch file. --------- You have completed the 2L Menu Bat File. It will be used in all the color Bat files. When a color appears on the screen it will always display the 2L Menu. COLOR CODES The next lessons use many of the DOS commands that you have learned thus far. The Batch files contain a good variety of color codes, parameters, and DOS commands. You will enjoy how fast these Speed keys operate. -10- WRITING THE COLOR CODE BAT FILES We'll Start With the Background Colors. Type the following next to the A> Prompt, Like this: Copy Con BLB.Bat (Black background)* Prompt $e[40m $p$g %1 Echo off Cls 2L.Bat Press F6 key, then press Enter key. --------------- Copy Con RB.Bat (Red background) Prompt $e[41m $p$g %1 Echo off Cls 2L.Bat Press F6 key, then press Enter key. ---------------- Copy Con GB.Bat (Green background) Prompt $e[42m $p$g %1 Echo off Cls 2L.Bat Press F6 key, then press Enter key. -------------- Copy Con YB.Bat (Yellow background) Prompt $e[43m $p$g %1 Echo off Cls 2L.Bat Press F6 key, then press Enter key. -------------- Copy Con BB.Bat (Blue background) Prompt $e[44m $p$g %1 Echo off Cls 2L.Bat Press F6 key, then presss Enter key. --------------- Copy Con MB.Bat (Magenta background) Prompt $e[45m $p$g %1 Echo off Cls 2L.Bat Press F6 key, then press Enter key. ---------------- -11- Copy Con CB.Bat (Cyan background> Prompt $e[46m $p$g %1 Echo off Cls 2L.Bat Press F6 key, then press Enter key. --------------- Copy Con WB.Bat (White background) Prompt $e[47m $p$g %1 Echo off Cls 2L.Bat Press F6 key, the press Enter key. --------------- In The Next Group Are The Codes For The Letters (Foreground). Copy Con BLK.BAT (Black letters) Prompt $e[30m $p$g %1 Echo off Cls 2L.Bat Press F6 key, the press Enter key. -------------- Copy Con R.Bat (Red letters) Prompt $e[1;31m $p$g %1 Echo off Cls 2L.Bat Press F6 key, then press Enter key. -------------- Copy Con G.Bat (Green letters) Prompt $e[1;32m $p$g %1 Echo off Cls 2L.Bat Press F6 key, then press Enter key. --------------- Copy Con Y.Bat (Yellow letters) Prompt $e[1;33m $p$g %1 Echo off Cls 2L.Bat Press F6 key, then press Enter key. ---------------- -12- Copy Con B.Bat (Blue letters) Prompt $e[1;34m $p$g %1 Echo off Cls 2L.Bat Press F6 key, then press Enter key. ---------------- Copy Con M.Bat (Magenta letters) Prompt $e[1;35m $p$g %1 Echo off Cls 2L.Bat Press F6 key, then press Enter key. ---------------- Copy Con CY.Bat (Cyan letters) Prompt $e[1;36m $p$g %1 Echo off Cls 2L.Bat Press F6 key, then press Enter key. -------------- Copy Con W.Bat (White letters) Prompt $e[1;37m $p$g %1 Echo off Cls 2L.Bat Press F6 key, then press Enter key. -------------- This ends the writing of Batch Files for the 1 and 2 letter color-codes. Go to Chapter 4 ...Testing Colors. -13- CHAPTER 4 TESTING THE COLOR CODES Type the following next to the A> Prompt, like this: W The monitor screen will show a white-lettered prompt. Now, type in BB for blue background, like this: BB The screen color will turn blue. You should have white letters on a blue background. ß Type these two colors: Y RB For yellow letters on a red background. Try other combinations. Either color can be first. You have 64 possible color combinations. Try various combinations and select the ones you like. SOME GOOD COLOR COMBINATIONS ARE: ß W BB (White letters on blue screen) ß Y RB (Yellow on red background) ß W YB (White on yellow background) NOTE: The yellow background color on some Monitors may not give a true yellow background color. It may look more of a reddish-brown. MAKING A PRINT-OUT COPY OF YOUR MENU If you would like a print-out copy of your Menu use the "Type" command and add the "Prn" for print. For example, to make a copy of the Menu 2L you would type the following next to the A> Prompt, like this: Type 2L.Bat >Prn Your printer will make you a copy of Menu 2L showing the one and two -lettered codes. USING THE COLOR CODES Adding background color first, gives better contrast between letters and background. Start with the background color, then add the different colors for the letters: for example, start by using a Red background, like this: RB The screen will turn red. -14- Now start to type in different colors for the letters, like this: B You should now see the A> Prompt turn Blue. Try this one: BLB Screen turns black. Now, add yellow letters. Y The screen displays yellow letters on a black background. ANOTHER EXAMPLE Type Dir and press Enter key. When the directory appears on the screen all of the lettering will be yellow and the background will be black. HERE'S MORE! If you use the same color for the background and the lettering, the color of the Prompt may not be visible. The best way to make the background and foreground colors blend is to clear the screen with the CLS command or your OFF command, so that you will have a black and white monitor. Enter the background first, and then add the letters. With most monitors, the blend is perfect and no Prompt is visible. The Off command is in a Batch File that is written like this: Copy Con Off.Bat Prompt $e[0m $p$g Cls Press F6 key, the press Enter key. If you can't find your A> Prompt, use your Off command to clear the screen. The screen should be cleared with the Off command after each combination. ------------- ==========================END OF CHAPTER 4 ============================ Press Esc Key and return to Menu. Select Chapter 5 "Keyboard Macros". -15- CHAPTER 5 KEYBOARD MACROS Using the F Function Keys (F1 to F10) ß Keyboard Macros ß Redefining Keys ß Writing Scan Codes ß One Keystroke Commands MACROS ARE DESIGNED TO SAVE KEYSTROKES. You can put one or several strings of command together and assign them as one group to one of the keys. When that key is struck it will carry out (execute) all the commands you assigned to that key. The F function keys (F1 to F10) are the keys most used for storing the Macros (Commands). The ten F function keys are also used in combination with the Shift key, Control key, and the Alt key. This gives 40 possible Macros that you can make. The F keys (F1 to F10) when used by themselves make a single keystroke Macro. This means that if you assign the F1 key the command to Format a disk, then when you strike the F1 key it will Format a disk. It does not require that you press the Enter key. Most Macros include the automatic carriage return which is the same as pressing the Enter key. When you combine an F key with the Shift key you make a two-keystroke Macro. To use a Shift-F key Macro you press and hold down the Shift key and then strike the F key. REDEFINING KEYS Redefining keys means changing the content of the key to represent something different from the function assigned to that key: For example, you can change the F1 function key (top row) to mean Copy, Format, or anything you like. The name of the key will still be F1, but you have changed the contents of F1 so that when you strike the F1 key it may Copy a file, Format a disk, or something else. Redefining keys is a good way of putting commands in keys that you don't use and make them a super Speed key that uses only one keystroke. Most Macros use the F keys first, then a combination then the Alt-F keys and Shift-F keys. Since these F keys will be used only for a particular command you can make the key have an Automatic Return. This means that when you strike a particular F key it will automatically trigger the return key. All you need to do is strike one key and the command goes into action. This type of key is called a single keystroke Macro. The F-key combinations (SHIFT-F1) are two keystroke Macros. -16- Macros are easily cancelled and can be redefined and made into another Macro. There are temporary Macros that you can create as you need them, and there are the permanent Macros that are stored on your disk. MACROS ARE FAST AND DO THE JOB Macros save keystrokes. Macros are used in almost all word processing programs, spreadsheets, database, and most other programs. A NOTE ABOUT F KEYS If you use the F6 key as a Macro you can make an F6 by using Ctrl + Z keys. This is the same as striking the F6 key. This is important when writing Batch files where the F6 key is used to end a line of text. EVERY KEY ON THE KEYBOARD HAS A CODE NUMBER By using the number (called a Scan Code) corresponding to the key you can change the content (assignment) of that key. The keyboard Scan Code for the F1 key is 0;59, F2 is 0;60, F3 is 0;61 and so forth to F10 which is 0;68. Table 1 is a list of redefinition code numbers (scan codes) to be used in redefining the F keys and combinations of F keys. TABLE OF KEY CODES F-Key Code SHIFT-F CODE CTRL-F CODE ALT-F CODE F1 0;59 SH-F1 0;84 Ctrl-F1 0;94 Alt-F1 0;104 F2 0;60 SH-F2 0;85 Ctrl-F2 0;95 Alt-F2 0;105 F3 0;61 SH-F3 0;86 Ctrl-F3 0;96 Alt-F3 0;106 F4 0;62 SH-F4 0;87 Ctrl-F4 0;97 Alt-F4 0;107 F5 0;63 SH-F5 0;88 Ctrl-F5 0;98 Alt-F5 0;108 F6 0;64 SH-F6 0;89 Ctrl-F6 0;99 Alt-F6 0;109 F7 0;65 SH-F7 0;90 Ctrl-F7 0;100 Alt-F7 0;110 F8 0;66 SH-F8 0;91 Ctrl-F8 0;101 Alt-F8 0;111 F9 0;67 SH-F9 0;92 Ctrl-F9 0;102 Alt-F9 0;112 F10 0;68 SH-F10 0;93 Ctrl-F10 0;103 Alt-F10 0;113 F11 0;133 Home Key 0;71 Down Arrow 0;80 F12 0;134 Up Arrow 0;7 WRITING SCAN CODES All code numbers are always separated by a semicolon. All codes must have this Prompt Escape sign: Prompt $e[ ..... There are four items to remember in using the Escape sign, they are: ß Prompt $e[ ß semicolon (;) ß The small "p" (tells DOS that it is end of file) ß The number 13 is the code for carriage return (Same as pressing the Enter key.) -17- Remember these four items and you'll have no problems with Macros or Key definition (Changes). HERE'S AN EXAMPLE Prompt $e[ 0;59; "DIR"; 13 p $p$g Putting them together it looks like this: Prompt $e[0;59;"DIR";13p $p$g The quotation marks tell the computer that the item in quotes is not an ASCII character. ß The $p$g gives you a prompt A:\>, and saves you from having to type the word prompt. ß The small "p" tells the computer that it is the end of the string of numbers and letters. ß The small "p" must always be the last item when you are using key functions. ß The character 13 is the code for carriage return (same as pressing the Enter key). HOW TO USE THE CODE NUMBERS Suppose you want to make the F1 key into the Directory so that each time you press the F1 key the directory of the disk in drive A would appear on the screen. You make the change like this: Prompt $e[0;59;"DIR";13p $p$g When you press the F1 key the computer automatically "presses" the Enter key for you and the contents of the directory appears on the screen. The F1 key will remain active until you either cancel it or turn off the computer. To make the F1 Macro permanent you must put it in the Autoexec.Bat File. AUTOEXC.BAT FILES AND LOADING THE F FUNCTION KEYS WITH MACROS IS PRESENTED IN DISK #2. HOW TO CANCEL AN F KEY The rule in cancelling any key that has been redefined (changed) is to repeat the same scan code like this: Prompt $e[0;59;0;59p $p$g The key is back to its normal F1 function. WRITING A BAT FILE FOR THE DATE AND TIME Type the following next to the A:\> prompt, like this: Copy Con DT.Bat Prompt $e[1;32;45m $d $t $g Press F6 Key, then press Enter key. ------------ -18- PUTTING THE DT BAT FILE INTO A MACRO (See disk #2 below) The Date-Time Bat file will be stored in the Up arrow key. The scan code for the Up arrow is 0;72. When you start the computer all the Macros in the Autoexec.Bat file automatically load the commands into the F keys and other keys, like the Up and Down arrow keys. ======================END OF LAST CHAPTER =================================== TO CREATE THE AUTOEXEC.BAT FILE AND OTHER PROGRAMS YOU MUST PURCHASE THE REGISTERED VERSION (DISK #2). SEE INTRODUCTION ON HOW TO ORDER THIS $10 DISK. -19- @Border A @Kborder @Dream WB Dir