Computer Help References version 1.19.95 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ B A T C H L A N G U A G E ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ As new information is added, it will appear at the beginning of each specific section. All new information will have the date it was added in the header. If you find something you've read before that is marked as a new addition, it is due to a correction, or addition to that topic. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ DOS Punctuation Primer ====================== -> Added on January 18, 1995 Symbol : `+' What it is : COPY file "concatenator". What it does : Tells the COPY command to combine the contents of several small files, or the contents of a file plus text you enter from the keyboard "console" (CON), into one big file. Uses : 1. To copy and combine both DOS startup files into one archive called STARTUP.FIL, type COPY AUTOEXEC.BAT+CONFIG.SYS STARTUP.FIL 2. To add a new line "REM End of file" to the bottom of your existing AUTOEXEC.BAT file without having to use a word processor or text editor, go to the DOS prompt and type COPY AUTOEXEC.BAT+CON REM End of File ^Z (For the ^Z, either hold down the CTRL key and press Z, or just press F6) and hit ENTER. 3. You can also use the + sign to make corners of crude comment boxes: +-------+ : : +-------+ Symbol : `:' What it is : Batch file label designator. What it does : Indicates a label designation for a GOTO command. Uses : 1. To see if your DOS directory contains a copy of DEBUG.COM or DEBUG.EXE, the DBUGHUNT.BAT batch file below uses :DEBUG_YES, :DEBUG_NO, and :END labels, which tells DOS where to jump to for each of the batch file's GOTO commands. @echo off REM This is DBUGHUNT.BAT IF EXIST \DOS\DEBUG.* GOTO DEBUG_YES GOTO DEBUG_NO :DEBUG_YES ECHO It's Here GOTO END :DEBUG_NO ECHO DEBUG is missing :END While you can use long labels, DOS only looks at the first eight characters, so to DOS, :LONGLABEL1 and LONGLABEL2 are the same (it sees both as :LONGLABE). If your batch file contains what DOS thinks are duplicate copies of the same label, it will always use the one closer to the beginning of the batch file. Labels must contain a colon (:) as the first character. Since DOS won't execute anything after a colon, you can also use colons as you would REM commands to add REMarks and comments to your batch files if you're careful. You could make the second line of DBUGHUNT.BAT read :This is DBUGHUNT.BAT However, if you had included a GOTO THIS command in the batch file, DOS might try to jump to such a comment line, thinking that ":This" was a label. So to be safe, if you DO use colons to leave comments, simply add a second colon such as ::This is DBUGHUNT.BAT 2. You can also use the colon to make sides of crude boxes. +-------+ : : +-------+ Symbol : `.' What it is : ECHO blank line generator. What it does : When used directly after the command ECHO with no extra spaces thrown in, it displays a blank line on screen. Uses : To have a blank line onscreen before and after the box around the following warning, use a pair of ECHO commands: @echo off REM This is MUSTDO.BAT ECHO. ECHO +-------------------+ ECHO : Back up every day!: ECHO +-------------------+ ECHO. The period after the ECHO is different from the one that DOS uses to preface a filename extension like .BAT or .EXE And it's also different from the single period that DOS uses to indicate the current directory, as it does in COMP B: . to have DOS COMPare the files on drive B: with those in the current directory. Note: This works with DOS 3.0 or later versions; earlier DOS versions handle ECHOing blank lines differently. Symbol : `@' What it is : Batch file display suppressor. What it does : Prevents batch files from displaying lines and cluttering up the screen unnecessarily. Uses : ECHO OFF will prevent all subsequent lines from displaying onscreen, unless a particular line is expressly designed to display something. But since this suppression capability doesn't go into effect until the line after the ECHO OFF, the ECHO OFF itself will normally display. Prefacing this (or any line) with an @ sign will prevent that one particular line from displaying. Generally, all batch files should begin with an @ECHO OFF line. These two batch files work essentially the same way: @ECHO OFF REM This is SILENT1.BAT ECHO Only this line will appear @REM This is SILENT2.BAT @ECHO Only this line will appear Note: This requires DOS 3.3 or later to work. Symbol : `>' What it is : Redirect-and-overwrite symbol. What it does : Redirects DOS output to a file and overwrites and existing file that happens to have the specified name. Uses : DOS can shift, or "redirect", the output of a file, device, or command from it's usual desination to a different file or device. When redirecting output to a file, using a single > sign creates a brand-new file and overwrites any existing file with the same name (see >>). 1. To print a DIR listing, type DIR > PRN 2. To suppress a "... file(s) copied" message after a COPY operation, add > NUL to the end: COPY *.* B: > NUL 3. To redirect the output of a DIR C: command and create a new file called DIRFILE (which would overwrite any existing file that has the same name), type DIR C: > DIRFILE If you subsequently typed DIR A: > DIRFILE DOS would wipe out the DIR C: contents of DIRFILE and create a new file containing just the directory listing of drive A: NOTE: This requires DOS 2.0 or later to work. Symbol : `>>' What it is : Redirect-and-append symbol. What it does : Redirects DOS output to a file and eithercreates a new file if one with the specified name doesn't already exist, or adds ("appends") the new information to the end of an existing file with the specified filename (see >). Uses : 1. If no file called DIRFILE already exists, the following line will create a brand-new DIRFILE file containing a DIR C: listing: DIR C: >> DIRFILE If a DIRFILE already exists, DOS will append a DIR C: listing to it. If you type DIR C: >> DIRFILE and then DIR A: > DIRFILE DOS will also append the directory listing of drive A: to the DIRFILE file. NOTE: This requires DOS 2.0 or later to work. Symbol : `<' What it is : Redirect-input-from-file symbol. What it does : While DOS normally expects input to come from the keyboard, in some cases you can tell it to use a file for input instead. Uses : To view the contents of a long text file called LONGTEXT.FIL, type MORE < LONGTEXT.FIL Be careful not to switch the < symbol around. Do *NOT* type MORE > LONGTEXT.FIL, or you will wipe out the LONGTEXT.FIL contents! NOTE: This requires DOS 2.0 or later to work. Symbol : `|' What it is : Pipe symbol. What it does : A DOS pipe makes the output of one command serve as the input for another command. Uses : 1. To view the contents of a long text file called LONGTEXT.FIL, type TYPE LONGTEXT.FIL | MORE Here the output of the TYPE command becomes the input for MORE. 2. To delete all the files in a directory and bypass the "Are you sure (Y/N)?" prompt, pipe the ECHOed keystroke Y into the DEL command: ECHO Y | DEL *.* Don't try this unless you really want to erase everything! 3. The most common pipe operation is to feed the FIND filter. To see a compact list of all your nonhidden subdirectories, type CHKDSK /V | FIND "Di" DOS 5.0 lets you try to do this with a new DIR switch: DIR \ /AD /S | FIND "Di" but this won't locate hidden subdirectories, either. NOTE: This requires DOS 2.0 or later to work. Symbol : `%0, %1 ... %9' What it is : Replaceable parameter. What it does : Lets a batch file use information sent to it from outside the batch file. DOS replaces any %0 it sees inside a batch file with the very first thing that appears on the command line after the DOS prompt. Since the first thing after the DOS prompt is the name of the batch file itself -- usually without the .BAT extension -- %) always represents the name of the batch file (at least initially; SHIFT can later change this). DOS replaces any %1 it sees in a batch file with the first thing you typed on the command line _after_ the name of the batch file. It replaces %2 with the second thing you typed after the batch file, and so on, up to %9. It uses "delimiters" to separate each thing you typed. The most common delimiter is a space, but DOS will treat semicolons, commas, and equal signs as delimiters too. SHIFT can later change the way DOS interprets these replaceable parameters. Uses : The following TALKBAK1.BAT batch file will display up to nine words that you enter at the DOS prompt after the word TALKBAK1; the first word will replace %1, the second %2 and so on. TALKBAK1.BAT uses the special parameter %0 to display the name of the batch file itself. @ECHO OFF REM This is TALKBAK1.BAT ECHO This is %0.BAT FOR %%A in (%1 %2 %3 %4 %5 %6 %7 %8 %9) DO ECHO %%A To have a batch file process more than nine replaceable parameters, use the SHIFT command. TALKBAK2.BAT will display as many words as you type on the command line after TALKBAK2. @ECHO OFF ECHO This is %0.BAT :TOP IF %1!==! GOTO END ECHO %1 SHIFT GOTO TOP :END While replaceable parameters are normally used to handle things that you type on the command line, they also work well with FOR ... IN ... DO %%A variables and CALL commands. In the following pair of batch files, BATCH1 calls BATCH2 and passes parameters from BATCH1 to BATCH2. BATCH1 will ferret out all the .BAT files in your directory and pass the names to BATCH2; BATCH2 will display the names one by one and then display the contents of the files. The %%A in BATCH1 is like the pitcher; the %1 in BATCH2 is like the catcher. @ECHO OFF REM This is BATCH1.BAT FOR %%A IN (*.BAT) DO CALL BATCH2 %%A REM This is BATCH2.BAT ECHO %1 MORE < %1 PAUSE Symbol : `%%A' What it is : FOR ... IN ... DO batch file variable. What it does : Lets the FOR ... IN ... DO command perform repeated operations inside a batch file on a set of files or commands. Uses : The DOSFILS1.BAT batch file will copy all your .COM, .EXE, and .SYS files from the current directory on drive C: to a floppy in drive B: @ECHO OFF REM This is DOSFILS1.BAT B: FOR %%A IN (C:*.COM C:*.EXE C:*.SYS) DO COPY %%A DOSFILS2.BAT will do this and the erase the originals: @ECHO OFF REM This is DOSFILS2.BAT B: FOR %%A IN (COPY ERASE) DO %%A C:*.COM FOR %%A IN (COPY ERASE) DO %%A C:*.EXE FOR %%A IN (COPY ERASE) DO %%A C:*.SYS NOTE: FOR ... IN ... DO variables require double %% prefixes when used in batch files, but just single % prefixes when used directly at the DOS prompt. Symbol : `%A' What it is : FOR ... IN ... DO nonbatch file variable. What it does : Lets the FOR ... IN ... DO command perform repeated operations on a set of files or commands on the command line at the DOS prompt. Uses : To see help for all the external DOS 5.0 commands (assuming your DIS files are all in a DOS directory), type FOR %A IN (\DOS\*.COM \DOS\*.EXE) DO %A /? NOTE: FOR ... IN ... DO variables require double %% prefixes when used in batch files, but just single % prefixes when used directly at the DOS prompt. Symbol : `%ENV_VAR%' What it is : Environemt variable. What it does : Lets your batch files use the DOS environment as a place to store variables, and gives batch files access to the important DOS settings already stored there (PATH, PROMPT, COMSPEC, and so on). Uses : The DOS PROMPT command can issue tricky ANSI.SYS color-setting Escape sequences. Normally this would change your PROMPT, but you can store a copy of the current prompt as an OLDPROMPT environment variable and then later retrieve the stored value as %OLDPROMPT% This works only from inside batch files. SHOWCOL.BAT assumes ANSI.SYS has already been loaded at boot-up time in CONFIG.SYS (with a like like DEVICE=\DOS\ANSI.SYS), and it will display six different foreground colors on a black background. Make sure you leave a blank line before the @CLS !! @REM This is SHOWCOL.BAT @SET O=%PROMPT% @PROMPT $E[0;40m @FOR %%A IN (6 5 4 3 2 1 1) DO PROMPT $E[3%%Am @PAUSE @PROMPT $e[34;47m @CLS @SET PROMPT=%O% NOTE: Environment variables were not documented before Version 3.3 and worked erratically (or not at all) in some earlier DOS versions. To use the environment as a variable storage area, you'll probably have to expand your default environment size with a line in your CONFIG.SYS like this one: SHELL=C:\DOS\COMMAND.COM C:\DOS\ /E:1024 /P Symbol : `==' What it is : IF string-test equal sign. What it does : Lets IF test whether two chracter strings are the same. Uses : All batch files that need user-entered parameters should start out with an "IF %1!==! GOTO OOPS" test: @ECHO OFF REM This is ANYBATCH.FIL IF %1!==! GOTO OOPS REM (Guts of batch file go here) GOTO END :OOPS ECHO You didn't enter anything! :END If the user enters anything at all on the command line after the name of the batch file, DOS replaces the %1 with what the user entered. If the user entered ANYBATCH Hi Mom DOS will make %1 equal to Hi, and will make the IF test: IF Hi!==! GOTO OOPS Hi! is not equal to !, so the test fails, and the batch file doesn't jump to :OOPS. But if the user doesn't enter anything after the name of the batch file, the test becomes IF !==! GOTO OOPS and since ! is clearly equal to !, DOS will jump to the :OOPS label. * PC Computing - DOS Power Tools from Paul Somerson ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Where to put the "PATH" Statement ================================= -> Added on January 12, 1995 Most people pud the PATH in the beginning of their AUTOEXEC.BAT Your PATH is stored in the environment (along with your PROMPT, COMSPEC, and whatever other environment variables you may set). Every TSR (Terminate and Stay Resident) program (like MOUSE.COM) that DOS loads gets a copy of the current environment. Because of this, the more you have in your environment when a TSR is loaded, the more memory that particular TSR will require. Therefore, it's best to load TSR's _before_ setting any environment variables. * Vernon.Frazee@f71.n135.z1.fidonet.org or FidoNet: 1:135/71 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Thinning Your AUTOEXEC.BAT ========================== -> Added on January 12, 1995 If you have a bunch of variables pointing to the TEMP directory (such as TMP, TEMP, LIST, etc.) there is a shortcut you can use. A powerful feature of BATCH language is the FOR xx IN ... DO ... command. Here's an example of setting 3 variables (TMP, TEMP, and LIST) to "C:\TEMP" -- all in one line. for %%x in (TEMP TMP LIST) do set %%x=c:\temp * Vernon.Frazee@f71.n135.z1.fidonet.org or FidoNet: 1:135/71 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Re-Booting your Computer ======================== -> Updated on January 3, 1995 -> Added on December 12, 1994 For MS-DOS, the following will reboot your computer ... echo G=FFFF:0 | DEBUG >NUL For DR-DOS, the following will reboot your computer ... echo GFFFF:0000 | SID >NUL Both of the above methods occassionally will give garbage and leave files sitting around. Another way is to use "echo HPS*>REBOOT.COM" to create a mini-program called REBOOT.COM You have to replace the * character above with --> Ë <-- If you can see an "outlined-T" that's what you want. You have to hold down the key and type "203" without the quotes to get that character. If you run a BBS, or have a Communications Fossil loaded, you can use whichever one of the following match your Fossil Driver ... If you are using BNU type: BNU /B If you are using XDO type: XU BOOT ********************************************************************** ** ** ** Flush your Disk Cache before you use any of these methods !!!! ** ** If you use Smartdrive, the command is: SMARTDRV /C ** ** ** ********************************************************************** * Unknown Source - Sorry! Here's a couple of programs you can cut and paste, feed into DEBUG and keep in your "Batch" directory. To use the following programs, you'll need to save everything between the two --->CUT HERE<--- lines *EXACTLY* as you see here, into a plain ASCII text file. Once that's done, at the DOS prompt, type DEBUG < filename where filename is the name of this script file (whatever you named the ASCII text file). Since there are two separate programs ... COLD.COM and WARM.COM, you will need to repeat the above instructions once for each area. ----------------------------->CUT HERE<----------------------------- N COLD.COM E 0100 B8 40 00 8E D8 B8 7F 7F A3 72 00 EA 00 00 FF FF RCX 0010 W Q ----------------------------->CUT HERE<----------------------------- ... and the second one ... ----------------------------->CUT HERE<----------------------------- N WARM.COM E 0100 B8 40 00 8E D8 B8 34 12 A3 72 00 EA 00 00 FF FF RCX 0010 W Q ----------------------------->CUT HERE<----------------------------- * Richard Dale @ 1:280/333 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Communicating With a Modem ========================== -> Added on January 3, 1995 A common question is how to communicate with a modem either in a batch file or on the command-line. After setting up the COM port with MODE (if it's required) simply use DOS redirection ">" to ECHO AT commands to the modem. mode COM1 baud=19200 data=8 parity=n stop=1 echo AT&FF10\N4&D3E0M0Q1S0=1&W0>COM1 The above example might be used to set up a modem loading a profile into it. Or if you wanted to leave a computer accessable from a remote location you might shell out of a communications program and run a batch file containing: %COMSPEC% /e:1024 >COM1 Added on January 3, 1995 Normally, whenever you put a Ctrl+Z in a batch file, that is where execution of the batch stops. This happens because Ctrl+Z is an End-Of-File Marker for DOS (EOF). Using EDLIN in a BATch often needs the Ctrl+Z to be entered into a script and one of the few ways to do this is from the command prompt. Type: SET ZED=(Ctrl+Z) Replacing the bracketed text with the real key combination. In BATch files thereafter you can use %ZED% where you are required to use a Control+Z key combination. Here's a quick example. This batch will search README.TXT and replace Microsoft with Mickey$loth. echo 1,#RMicrosoft%ZED%Mickey$loth>test.scr echo e>>test.scr edlin README.TXT Added on January 3, 1995 Normally, FOR-loops cannot be nested. If they could, we could say: for %%f in (h H /?) do for %%g (// -) do if "%1"==(%%g%%f) goto @Help It *is* possible to nest FOR loops, by using COMMAND /C... for %%f in (h H /?) do command /c for %%g in (// -) do if "%1"==(%%g%%f)... ...goto @Help * Steve Reid @ 1:153/414 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Testing for Command Line Arguments ================================== -> Added on January 3, 1995 The %PATH% variable is a handy little item. To enter ... set path=c:\bat;c:\dos;c:\util you would end up with ... %path%==c:\bat;c:\dos;c:\utl however, to enter ... path c:\bat;c:\dos;c:\utl you would end up with ... %path%==C:\BAT;C:\DOS;C:\UTL Subsequently, in a batch file, you have an obvious "short-cut" ... [...] set oldpath=%path% path %1 set parm1= for %%a in (WAHTEVER RANGE YOU LIKE) do if %%a==%path% set parm1=%%a path %oldpath% set oldpath= if (%parm1%)==() goto Invalid_Parm [...] Imagine trying to test for all possible combinations of the word RANGE.. ie. Range RAnge ranGe ... and so on! * Peter Lovell @ 3:640/302 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Asking for Help =============== -> Added on January 3, 1995 If you are making your batch file "user friendly", you'll probably want to supply some kind of help option. The trouble is, there are many ways of adding parameters to a command line. The following example should cover all possible "help" commands ... /? /H -? H etc. @echo off for %%f in (h H /?) do if "%1"=="-%%f" goto @SyntaxInfo for %%f in (h H /?) do if "%1"=="/%%f" goto @SyntaxInfo for %%f in (h H /?) do if "%1"=="%%f" goto @SyntaxInfo ... Your Batch File Here ... :SyntaxInfo ... Whatever Help You Wish to Provide ... Notice the "/?" in the FOR set. People made me understand the use of the forward slash in FOR sets, it sends a single character from the string. * Rene Verhagen @ 2:512/250.1243 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Just a Few Tidbits ================== -> Added on January 3, 1995 After puzzling over a few commonly asked questions, this is the result. When compared to other methods they reduce the number of lines required in a batch file. Examples using MS-DOS 6.22 (1) To save starting directory and return to it afterwards ... echo exit|%comspec%/k PROMPT @$N:$_@CD $P$_>c:\tmp.bat :: :: .... batch file commands go here .... :: for %%x in (call del) do %%x c:\tmp.bat (2) To set day of week in environment variable DOW ... echo exit|%COMSPEC%/K prompt SET DOW$Q$D$E[11D$E[K$_@>c:\tmp.bat for %%x in (call del) do %%x c:\tmp.bat (3) To set time in environment variable TIME ... echo exit|%COMSPEC%/K prompt SET TIME$Q$T$_@>c:\tmp.bat for %%x in (call del) do %%x c:\tmp.bat * Michael Druett @ 3:771/425 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Getting the Date into Variables =============================== -> Added on January 3, 1995 Here's something that may be useful to someone. This .BAT will take the date and put it into the variables YY, MM and DD. You can then display the date in whatever format you want. Uses the "/" MUF of the FOR command. :DATEFORM.BAT by Steve Reid @if %1.==swr. prompt set date=$d @if %1.==swr. goto end @echo off command /c %0 swr>%temp%\xtempx.bat call %temp%\xtempx.bat del %temp%\xtempx.bat echo %date% for %%i in (%date%) do set yy=%%i set var=z :loop set var=%var%x for %%i in (/%yy%) do set date=%%i for %%i in (/%yy%) do if not %%i.==%date%. set %var%=%%i set yy=%date% if not %var%==zxxxxxxxx goto loop set mm=%zx%%zxx% set dd=%zxxxx%%zxxxxx% for %%i in (var date zx zxx zxxx zxxxx zxxxxx) do set %%i= for %%i in (zxxxxxx zxxxxxx zxxxxxxx zxxxxxxxx) do set %%i= echo %yy%%mm%%dd% :end It uses a significant amount of environment space, but it still works with a 256 byte environment if most of it is free, probably doesn't even need that much. * sreid@sea-to-sky-freenet.bc.ca or FidoNet: Steve Reid @ 1:153/414 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Need the Time and Date? ======================= -> Added on January 3, 1995 Add the following lines to any batch file to get the current date & time. @ECHO OFF ECHO | MORE | TIME | FIND /V "new" ECHO | MORE | DATE | FIND /V "new" * jamie.hermans@tech-spk.alive.ampr.ab.ca or FidoNet: Jamie Hermans @ 1:342/707 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Additional Environment Variable Space ===================================== -> Added on December 12, 1994 This is a guaranteed method of creating a larger default environment variable space for EACH copy of COMMAND.COM that is loaded. Some people may experience an out of environment error when running batch files from another program. This is a sure fix, but also a permanent one! When a new version of MS-DOS comes out, this fix will cause the update program to abort. Make sure you have a back-up copy of the original for when this time comes. This example is specific to MS-DOS version 6.22 COMMAND.COM of 54,645 bytes. The date and time of the file should be May 31, 1994 at 6:22am respectively. See the end of this section for instructions for finding patch points in different versions of COMMAND.COM @echo off :: THIS ONLY WORKS FOR ... COMMAND.COM 54,645 05-31-94 6:22a :: make changes to "C:" and "CD\DOS" as needed in the next two lines c: cd\dos if exist command.pat echo It seems you have already patched this version! echo. if exist command.pat type command.pat if exist command.pat goto end copy command.com command.256 >nul echo Patched COMMAND.COM on date shown on next line:>command.pat ver|date|find "Curr">>command.pat echo e1777 40>>command.pat echo w>>command.pat echo q>>command.pat attrib -r -h -s command.com debug command.com * Gerry Pareja @ 1:153/151 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Patch Points in COMMAND.COM =========================== -> Added on December 12, 1994 If you like the idea of being able to patch COMMAND.COM, but you don't have the version used above ... here's the various addresses for this patch in the various versions of MS-DOS. Ver Date Time Size Offset Default Size --------------------------------------------------------------------- MS-DOS 3.30 02-02-88 12:00am 25038 0DB8h 0Ah (160 bytes) PC-DOS 3.30 03-17-87 12:00pm 25307 0DB8h 0Ah (160 bytes) MS-DOS 4.01 12-19-88 12:00am 37557 1B2Ah 0Ah (160 bytes) MS-DOS 5.00 04-09-91 5:00am 47845 1566h 10h (256 bytes) MS-DOS 5.00 03-22-91 5:10am 47845 1566h 10h (256 bytes) MS-DOS 6.00 03-10-93 6:00am 52925 1667h 10h (256 bytes) MS-DOS 6.20 09-30-93 ?:???m ????? 1677h 10h (256 bytes) MS-DOS 6.22 ??-??-?? ?:???m ????? 1677h 10h (256 bytes) (Add 100h to the >offset< if using DEBUG to patch COMMAND.COM) ( See sample instructions below patching MS-DOS 5.0 ) For those unfamiliar with patching, make sure you have a boot floppy available in case of an error. Copy COMMAND.COM to something like COMMAND.ORG. Then, at the Dos prompt, if you want a 384 byte environment, type: DEBUG COMMAND.COM <-- you will see a "-" prompt. Type: E 1666 18 <-- followed by Enter W <-- followed by Enter. You will see "Writing.." etc Q <-- which exits DEBUG Various environment size values: 01h = 16 bytes 40h = 1024 bytes 10h = 256 bytes (default) 60h = 1536 bytes 20h = 512 bytes 80h = 2048 bytes 30h = 768 bytes FFh = 4080 bytes * Jeff Brielmaier @ 1:106/4100 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Freeing up Environemt Space =========================== -> Added on December 12, 1994 In Autoexec.bat, add the line: set dummy=1234567890123456789012345678901234567890 ... (or longer if you wish) then, in _every_ batch file that is run in a shell, release that variable by using: set dummy= which immediately releases 50 or more bytes to the current environment. * Gerry Pareja @ 1:153/151 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Changing an ErrorLevel into a Variable ====================================== -> Added on December 12, 1994 Is there any way to echo an errorlevel? There're several batch methods around which will accomplish this. Here's the one I use: @echo off for %%x in (0 1 2) do if errorlevel %%x00 set el=%%x if not %el%==2 goto not200 for %%x in (0 1 2 3 4 5) do if errorlevel %el%%%x0 set el=%el%%%x if not %el%==25 goto not250 for %%x in (0 1 2 3 4 5) do if errorlevel %el%%%x set el=%el%%%x goto done :not200 for %%x in (0 1 2 3 4 5 6 7 8 9) do if errorlevel %el%%%x0 set el=%el%%%x :not250 for %%x in (0 1 2 3 4 5 6 7 8 9) do if errorlevel %el%%%x set el=%el%%%x :done echo Errorlevel is %el% It sets a three digit environment variable called EL to the current value of the errorlevel, left padded with zeroes. Here's a little programme to test it with. I believe it was written by John Gray. SEL.ZIP contains SETEL.COM, which can be used to set an errorlevel. The syntax is simply SETEL 99 (to set the errorlevel to 99). To use the following program, you'll need to save everything between the two --->CUT HERE<--- lines *EXACTLY* as you see here, into a plain ASCII text file. Once that's done, at the DOS prompt, type DEBUG < filename where filename is the name of this script file (whatever you named the ASCII text file). ----------------------------->CUT HERE<----------------------------- NSEL.ZIP E100 FC BB 03 00 BF D4 01 BE CC 01 33 C9 AD 86 CC AA FE C0 E2 FB 4B E115 75 F5 B9 FF FD BA 20 02 52 B4 3F CD 21 5F 72 60 8B F7 50 8B C8 E12A B0 2A F2 AE 75 55 B0 0D F2 AE 87 F7 BB 00 01 B2 04 AC 3C 2A 72 E13F 62 74 46 57 BF D2 01 B9 40 00 8A E1 F2 AE 5F 75 35 FE C1 2A E1 E154 88 27 43 FE CA 75 E0 56 BE 00 01 AD 86 C4 8B D0 AD 86 C4 5E B1 E169 02 D2 E0 D3 E0 D2 E2 D3 EA D0 E1 D1 EA D1 D8 E2 FA 86 C2 AA 8A E17E C4 AA 8A C2 AA EB B1 BF 20 02 58 33 D2 F7 D8 13 D2 F7 DA 33 DB E193 8B CA 8B D0 B8 01 42 CD 21 8B 0E CA 01 CC AC 3C 0A 75 FB AC 57 E1A8 BF D2 01 B9 40 00 8A E1 F2 AE 5F 75 D0 FE C1 2A E1 86 E0 32 E4 E1BD 8B 1E CA 01 03 D8 89 1E CA 01 E9 6C FF 00 00 30 0A 41 1A 61 1A E1D2 2B 2D G=100 W220 Q GXDPlus 1.0 *XXBUG20--00000198--27111994--BD201A56------------------SEL.ZIP nI2g1--E++++6++eaRljKgDjI7+2++4k-+++7++++IoJIFIkiEoxBJMwlGwBE36IX046Y nWsjf3FlOf-c85GfR72UZK6WGzNZQYkTBSy4y3oEF4hnOeNiCzcUWcdAzE5-o3b5k-nVo noNQWK8Q1VyyQQyxhOLIgjRBN54nS17yuXtMpT9qnFxRLJXZp9xT8OLikKbuuLlyoMfrE nohvPywFzLbzc9YmKXNEniTwqpd3rv+JyuAAiN3kd9V8E-3l2YUUX1JsEx+9T0noTQYMg nEsrYq-hnAJbcjDU58hGU7HFP9ICClrCgHfa0b4FWaWdA4ETbcnJrmwHeQ2cm+wRaI3rI nlvzh-dmZD2cV8tG42kEdgBfG8G40816Y5dZUn-BiqfaM1F+H0M9vSlHIygXWuhA978a+ nFF5a4iDuhaATm3H+Df5n-fWhkpvMPXfq1p-9+E6I+-E++++6++eaRljKgDjI7+2++4k- n+++7++++++++++2+6+++++++++-HFJF3H0t1HopEGkI4++++++2++E+r++++Gk2+++++ *XXBUG Version 2.20 by Chad Wagner ----------------------------->CUT HERE<----------------------------- * John Evans @ 2:2433/506 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ ANSI Control Codes ================== -> Added on December 12, 1994 An ANSI control code can do lots of things. Each ANSI code has the same basic format. First is the escape command. We will show it as ESC in this text. In an ASCII editor, it can be entered into a batch file by typing 027 while holding the ALT key down. Next is the "[" character. Then the parameters. Be sure to pay attention to upper and lower case letters in the parameters. ESC[2J - To clear the screen and home the cursor ESC[#;*H - To locate the cursor to row #, column, * ESC[#A - To move the cursor up # rows ESC[#B - To move the cursor down # rows ESC[#C - To move the cursor right # columns ESC[#D - To move the cursor left # columns ESC[s - To store the current cursor position ESC[u - To return to the stored cursor position ESC[#;...;#m - To set a color and attribute use #;...;# which is a list of attributes. Replace # IN ESC[#;...;#m with the value for the desired attribute, separating multiple parameters with a semi-colon. The ;# sequence sets the colour according to the following table: Fore Back Colour 30 40 - Black 31 41 - Red 32 42 - Green 33 43 - Yellow 34 44 - Blue 35 45 - Magenta 36 46 - Cyan 37 47 - White The ;#m sequence sets the attribute according to the following table: 0 - All attributes off (normal white-on-black) 1 - Bold on (high intensity) 4 - Underscore on (monochrome display only) 5 - Blink on 7 - Reverse video on 8 - Cancelled on (invisible, not demonstrated) The ESC[=#h sequence sets screen modes according to the following table: 0 - 40x25 black & white 1 - 40x25 color 2 - 80x25 black & white 3 - 80x25 color 4 - 320x200 color 5 - 320x200 black & white 6 - 640x200 black & white 7 - Line Wrap On (typing beyond end of line starts new line) ANSI codes can be used by adding them to the text you send to the display with the ECHO command. For example, a blinking yellow on blue HELLO can be obtained with the line: "ESC[33;44;1;5mHELLOESC[0m" * Unknown Source - Sorry! ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Let X=X+1 ?!? ============= -> Added on December 12, 1994 Pure MS-DOS won't allow math evaluation. N/4DOS will or some other utility may allow you to do a calculation, but here is a batch file to let you do JUST that. Enjoy!! @echo off :: :: REPEAT.BAT -- by R.Neve, released into the Public Domain 26/11/94 :: :: Needs DEBUG.EXE and FIND.EXE in the path :: Syntax: REPEAT {n} {c1 [, c2, c3, ..., c8]} :: where : - {n} is the number of iterations, expressed using the following :: formula: 2n+14 (n=number of iterations), for example, let's :: you wanted to run repeat 20 times, you'd write: 2*20+14=54 :: - {c1 [, c2, c3, ..., c8]} is the command using up to 8 elements :: which you want to repeat the specified number of times. :: It can be any valid dos command or program with params, but :: only the first 8 elements are taken into account :: :: Ex: Do a 'DIR' five times (very useful!!): :: :: REPEAT 24 dir c:\ /-p :: | ^^^^^^^^^^^- command to repeat 5 times. :: | :: +- 5*2+14=24 :: if '%1'=='' goto syntax echo r cx > debug.scr echo 5>> debug.scr echo w>> debug.scr echo q>> debug.scr echo @set size=%%2>#2.bat :do_command echo call >#1.bat debug #1.bat < debug.scr > nul if '%size%'=='%1' goto end echo.>>#2.bat %2 %3 %4 %5 %6 %7 %8 %9 dir /-p #2.bat|find /i "#2"|find /i "bat" >> #1.bat call #1 goto do_command :syntax echo REPEAT þ Sept'94 - R.Neve echo ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ echo Syntax: REPEAT {n} {c1 [, c2, c3, .., c8]} echo where : {n} is number of iterations*2+14 echo ex: for 30 iterations, enter 30*2+14=74 echo {c1 ...} is a commands (up to 8 elements) to execute echo the specified number of times echo. goto quit :end for %%a in (#1.bat #2.bat debug.scr) do del %%a set size= :quit cls * Raphael Neve @ 2:321/1 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Saving the Current Directory - Part 1 ===================================== -> Added on December 12, 1994 Paste the following three lines into your batch file at any stage where you are at the drive:\dir you'd like to return to. echo @prompt @echo off$_$n:$_cd $p>%temp%\temp.bat %comspec% /c %temp%\temp>c:\bat\pop.bat del %temp%\temp.bat Then later in your batch file, when you'd like to pop back to where you were, simply past in the following line. call c:\bat\pop * Peter Lovell @ 3:640/302 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Saving the Current Directory - Part 2 ===================================== -> Added on December 12, 1994 Thanks to Gerry Pareja who taught me how to redirect the command prompt to accomplish tricks in batch files. You can customize your command prompt to include information about the current drive, directory, time, date, ">", "<", "|", "=", etc. The idea is to create a "magic prompt" that reads like a batch file, then get it into a batch file. And it doesn't even change your "real" prompt! It takes three steps. STEP 1: echo @prompt PromptString > temp1.bat Now temp1.bat has one line, a prompt command. Pick the PromptString to write the "magic prompt" that you need. Some examples and the prompt they create are: @prompt $n:$_CD $p D: CD D:\BBS\BWAVE @prompt SET CURR$Q$p SET CURR=D:\BBS\BWAVE You might want to issue these prompt commands interactively (without @) to better understand how this works. STEP 2: command /C temp1.bat > temp2.bat Now temp2.bat has 2 or more lines. The first line is blank. The other lines contain the magic prompt we composed in step one. We have turned the prompt into a real batch file! STEP 3: call temp2.bat This uses the batch file. Notes: For a complete implementation you may want to erase the work files. For speed you might put the work files onto a RAM disk. For some purposes you might want to insert additional work between steps two and three. If those additional steps change the current directory, then you need to know where "temp2.bat" was created - perhaps as %TEMP%\temp2.bat. * William Lipp @ 1:141/1295 ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Naming Batch Files ================== -> Added on December 7, 1994 A batch file can have any legal DOS filename as long as it ends in .BAT and doesn't conflict with other similar filenames or commands in your system. When it sees files with similar names, DOS will always execute the ones that end in .COM and .EXE before it runs one ending in .BAT Unless you get tricky, you can't have DOS run batch files with names similar to "internal" DOS commands. Internal commands are the ones actually contained inside the main COMMAND.COM file (PROMPT, DIR, CALL, CHCP, RENAME, REN, ERASE, DEL, TYPE, REM, COPY, PAUSE, DATE, TIME, VER, VOL, CD, CHDIR, MD, MKDIR, RD, RMDIR, BREAK, VERIFY, SET, PATH, EXIT, CTTY, ECHO, GOTO, SHIFT, IF, FOR, CLS, LOADHIGH, LH, OR TRUENAME). Starting with Version 5.0 of MS-DOS, DOS will also run DOSKEY macros before batch files with similar names ... It's tough being a batch file! Try to keep the names short, easy to remember, and easy to type. The eight-character name limitation can be vexing, especially for a long batch file that does something complex, but try your best. These things are supposed to make life easier, not more difficult. * PC Computing - DOS Power Tools from Paul Somerson ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Quick Tour ========== -> Added on December 7, 1994 Technically, DOS provides just eight basic batch file commands -- CALL, ECHO, FOR, GOTO, IF, PAUSE, REM, and SHIFT -- plus a tiny assortment of miscellaneous doodads: replaceable parameters, environment variables, labels, double == signs, and @ signs. That's it! Not too much to learn, even for the most fervent DOS-hater. But the tools these few commands can create will astonish you. The quickest way to learn the "doings" and syntax for each of the commands is too use MS-DOS's HELP program. Want to check out CALL? Type either CALL /? or HELP CALL at the prompt and DOSS will display either a few lines of help (CALL /?) or open up it's reference database (HELP CALL) with examples and usage syntax. * PC Computing - DOS Power Tools from Paul Somerson ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Environment Variables ===================== -> Added on December 7, 1994 The DOS SET commands gives you and your batch file access to a special area of memory called the DOS environment. DOS normally uses the environment as the place to store its own important settings for your PATH, PROMPT, and COMSPEC. Typing SET all by itself will show you the current values of these three settings, plus settings for anything else that has been defined in the environment. If you will be using the environment for your own variables (covered later on in this text), you should increase the space allocated by CONFIG.SYS. Use the command SHELL=C:\DOS\COMMAND.COM C:\DOS\ /E:1024 /P in your CONFIG.SYS to boost the default to 1024 bytes. Once you've given yourself some environment elbow room, you can use it to store your own variables. You can put variables in there, either directly at the DOS prompt, or from inside batch files, by using the SET command. To create a variable called MAG and give it a value of PCC you would type SET MAG=PCC DOS automatically capitalizes the environment names themselves (in this case, the name is MAG), but not the values themselves. Therefore, the above command is the same as typing set mag=PCC However; if you typed SET MAG2=pcc the value of MAG2 would be lowercase pcc. Once you set an environment variable like MAG, you can change the setting by simply using the SET MAG= command again. Each successive SET MAG command wipes out the previous one. Remember, you can always see the current settings by typing SET at the DOS prompt. To erase any setting, type SET followed by the variable name and an equal sign with nothing after it. To remove the MAG variable and it's current value from the environment, type SET MAG= Because space is limited, it's always a good idea to have your batch files clean up after themselves by removing all variables if they are not needed later. * PC Computing - DOS Power Tools from Paul Somerson ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ