search for ccna answer

Wednesday, June 11, 2008

IF and IF NOT commands in batch file

There are three variations of the IF and IF NOT commands.

  • IF EXIST: Execute the commandline only if a particular file exists:

    IF EXIST some.txt COPY c:/some.dll %windir%/SYSTEM/some.dll

  • Compare two text strings, and execute the commandline only if they are identical.

    IF %HostWinBootDrv%==C SET WinDir=C:\WINDOWS

  • Error testing: Check the exit code of the most recently run program. If it is equal to or greater than the number specified, execute the command:

    IF ERRORLEVEL 4 ERASE trashfile.tmp /P

The better way to understand this command is try it yourself.
If got any question, post it here. I will try my best to solve it.

No comments: