home *** CD-ROM | disk | FTP | other *** search
- This topic contains miscellaneous hints for making BATCH files execute faster.
-
- Displaying information on the screen
- ------------------------------------
-
- To display information on the screen, TYPE a previously created file rather
- than using a long series of ECHO commands. You can also COPY the file to the
- device name CON.
-
- Exiting from a long BATCH file
- ------------------------------
-
- To immediately exit from a NESTED or CHAINED BATCH file (see the SUBROUTINES
- topic for information on these terms), just execute an EXIT command. It is not
- necessary to GOTO the last statement of the BATCH file. However, since a BATCH
- file executed directly from the keyboard ignores EXIT commands and continues
- until the last command is executed, there are two ways to speed up termination.
-
- Terminate by GOTO Terminate by CHAINing
-
- Insert a GOTO command at the point in Before using the BATCH file, create
- the BATCH file where the decision to an empty BATCH file, and chain to
- terminate is made, referencing a label that file at the point in the BATCH
- which is defined on the last line of file where the decision to terminate
- the BATCH file. The remaining lines in is made. This is faster than the GOTO
- the BATCH file will be still be read, method for long BATCH files, but
- but not executed. requires advance planning.
-
- some commands To create an empty BATCH file:
- GOTO EEXXIITT
- . REM > \EEXXIITT.BAT
- .
- . To chain to the empty BATCH file:
- some more commands
- . some commands
- . \EEXXIITT
- . .
- :EEXXIITT .
- .
- .
- some more commands
-
- Testing for the presence of replaceable parameters
- --------------------------------------------------
-
- In a BATCH file with multiple replaceable parameters, if %N is present, then
- all preceding parameters (%0, %1, ... %N-1) are guaranteed to be present. It
- is not necessary to test for the presence of each one, just the last one.
- Also, to test for the presence of replaceable parameter %N, use a test of the
- form "IF X==X%N command" where X is a short string. This IF will only test
- TRUE if %N is not present.
-
- Testing a long list of values
- -----------------------------
-
- Rather than a long series of IF commands, each testing for a value, use a
- FOR command. For example, the series of IF commands
- IF %2==YES GOTO goodvalu
- IF %2==Yes GOTO goodvalu
- IF %2==yes GOTO goodvalu
- IF %2==ok GOTO goodvalu
- IF %2==OK GOTO goodvalu
- IF %2==Ok GOTO goodvalu
- IF %2==Y GOTO goodvalu
- IF %2==y GOTO goodvalu
- could be replaced by one FOR command
- FOR %%a IN (YES Yes yes ok OK Ok Y y) DO IF %2==%%a GOTO goodvalu
-
- Condition code testing
- ----------------------
-
- In a BATCH file that tests the ERRORLEVEL set by the BACKUP, RESTORE, REPLACE,
- or other commands that set ERRORLEVEL, use a FOR command rather than a series
- of IF commands.
- IF ERRORLEVEL 5 GOTO error5
- IF ERRORLEVEL 3 GOTO error3
- IF ERRORLEVEL 1 GOTO error1
- REM if ERRORLEVEL is 0, the BATCH file will reach here...
- GOTO continue
- :error5
- .
- .
- .
- :continue
- could be replaced by one FOR command
- FOR %%E IN (5 3 1) DO IF ERRORLEVEL %%E GOTO error%%E
- REM if ERRORLEVEL is 0, the BATCH file will reach here...
- GOTO continue
- :error5
- .
- .
- .
- :continue