home *** CD-ROM | disk | FTP | other *** search
- SAMPLE command and resulting output | Comments about the output
-
- IF EXIST T.SAV COPY T.SAV \T.NEW If a file named T.SAV exists in the
- current directory, a copy called
- T.NEW will be made in the root
- directory.
-
- IF NOT EXIST %1 IF EXIST %1\NUL GOTO ITSDIRECT
- If replaceable parameter %1 is a
- directory (empty or not), this test
- will succeed. If %1 is a file, or
- does not exist, this test will fail.
- Using *.* instead of NUL, this test
- would fail for an empty directory.
-
- IF X==X%2 ECHO Name missing If the second replaceable parameter
- IF NOT X==%2X GOTO NAMEGOOD was absent when the BATCH file
- containing this command was
- executed, "Name missing" would be
- displayed, and the GOTO would not
- be executed. If %2 had any internal
- spaces, both IF commands would fail.
- However, if %2 has leading spaces, or
- was all spaces, the test
-
- IF X==%2X
-
- would fail.
-
- IF Hello==%1 GOTO NEWUSER In a BATCH file executed with the
- first replaceable parameter equal
- Hello, the GOTO would be executed.
- If the first replaceable parameter
- were anything else, the GOTO would
- not be executed.
-
- IF %SWITCHAR%==- DIR -W %1 If the DOS option character has been
- IF %SWITCHAR%==/ DIR /W %1 changed to "-", execute the DIR
- command with the -W option. If it
- is the normal "/", execute the DIR
- command with the /W option. Note that
- a more compact way to do this is
-
- DIR %SWITCHAR%W %1
-
- IF ERRORLEVEL 3 IF NOT ERRORLEVEL 4 EXIT Since the ERRORLEVEL condition tests
- for greater than or equal to, and IF
- commands can be nested, this is how
- to test ERRORLEVEL equal to 3, and
- if it is, to EXIT the batch file.
-
- IF NOT ERRORLEVEL 2 EXIT IF ERRORLEVEL less than 2, EXIT the
- batch file.
-
- IF NOT ERRORLEVEL 1 ECHO Success! IF ERRORLEVEL equal 0, display
- Success! on the screen.