IF-ERRORLEVEL usage

Source: Internet
Author: User

IF-ERRORLEVEL

Create TEST4.BAT with the following content:
@ ECHO OFF
Xcopy c: \ AUTOEXEC. bat d :\
If errorlevel 1 ECHO file copy failed
If errorlevel 0 ECHO, the file is successfully copied.
Then execute the file:
C: \> TEST4
If the file is successfully copied, the screen displays "successfully copied file"; otherwise, the screen displays "file copy failed ".
If errorlevel is used to test the return value of the previous DOS command. Note that it is only the return value of the previous command, and the return value must be determined in order from large to small.
Therefore, the following batch file is incorrect:
@ ECHO OFF
Xcopy c: \ AUTOEXEC. bat d :\
If errorlevel 0 ECHO, the file is successfully copied.
If errorlevel 1 ECHO does not find the copy object
If errorlevel 2 ECHO, the user uses ctrl-c to stop the copy operation.
If errorlevel 3 ECHO preset Error Blocking file copy operation
If errorlevel 4 ECHO disk write error during copy process
Whether the copy is successful or not, the following:
Copy file not found
You can use ctrl-c to stop the copy operation.
Preset errors prevent file copy operations
An error occurred while writing the disk during the copy process.
Are displayed.
The return values of several common commands and their meanings are as follows:
Backup
0 successfully backed up
1 backup file not found
2. File Sharing conflicts prevent backup from being completed
3. Use ctrl-c to stop the backup.
4. the backup operation is aborted due to a fatal error.
Diskcomp
0 disks are the same
1 disk is different
2. You can use ctrl-c to stop the comparison operation.
3. The comparison operation is aborted due to a fatal error.
4 preset error abort comparison
Diskcopy
0 disk copy operation successful
1 non-fatal disk read/write error
2. You can use ctrl-c to end the copy operation.
3. the disk copy is aborted due to a fatal processing error.
4. The copy operation is blocked due to a preset error.
Format
0: formatted successfully.
3. Use ctrl-c to stop formatting.
4. The format is aborted due to a fatal processing error.
5. When "proceed with format (y/n)?" is displayed )?" End with user input n
Xcopy
0 successfully copied the file
1 copy file not found
2. You can use ctrl-c to stop the copy operation.
4. preset errors prevent file copy operations
5. An error occurred while writing the disk during the copy process.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.