Web Hosting, Design, & Coding forum


Need ErrorLevel Help in Batch File.

by imaur2 / August 15, 2011 11:51 PM PDT

Hi, I'm trying to create a batch file that will stop the xcopy and
delete batch process and return a "Drive Full" statement, if there is
not enough space on my destination drive. This is what I have so far:


@echo off
set INPUT=
set /p INPUT= Enter PREVIOUS Date (ddmmyyyy) for which you want to create an ARCHIVE folder:
md h:\archive\graphics\%INPUT%
xcopy "i:\*.*" "h:\archive\graphics\%INPUT%" /D /E /R /I /K /-Y || goto Error
echo y | rd /s /q i:\DailyWork
echo y | del i:\Clients.xls
echo The Archive Drive is FULL! STOPPING Backup Procedure.

The batch file does stop, when the backup drive is full, but instead of
showing the error statement about the drive being full, I get a message
that instead states --

"Insufficient disk space on current disk.Insert another disk and type <Return> to continue..."

-- and I have to hit the "X" control button in the upper right of the
batch's pop-up window to close out of and exit the batch file. I've
also tried the following variations, but the batch file ended with the
same result:

1) xcopy "i:\*.*" "h:\archive\graphics\%INPUT%" /D /E /R /I /K /-Y || goto :Error (adding the colon before the word Error)

2) xcopy "i:\*.*" "h:\archive\graphics\%INPUT%" /D /E /R /I /K /-Y if %ErrorLevel% GTR 0 goto Error

From what I understand, batch file exit codes go from 0 to 5, and the code
pertaining to insufficient disk space is 4 ... but to be save, I should
have any code greater than 0 stop my xcopy/delete batch.

I would greatly appreciate any help in correcting my coding syntax for this batch file. Thanks so much!

~ Sally Happy

Discussion is locked
You are posting a reply to: Need ErrorLevel Help in Batch File.
The posting of advertisements, profanity, or personal attacks is prohibited. Please refer to our CNET Forums policies for details. All submitted content is subject to our Terms of Use.
Track this discussion and email me when there are updates

If you're asking for technical help, please be sure to include all your system info, including operating system, model number, and any other specifics related to the problem. Also please exercise your best judgment when posting in the forums--revealing personal information such as your e-mail address, telephone number, and address is not recommended.

You are reporting the following post: Need ErrorLevel Help in Batch File.
This post has been flagged and will be reviewed by our staff. Thank you for helping us maintain CNET's great community.
Sorry, there was a problem flagging this post. Please try again now or at a later time.
If you believe this post is offensive or violates the CNET Forums' Usage policies, you can report it below (this will not automatically remove the post). Once reported, our moderators will be notified and the post will be reviewed.
Popular Forums
Computer Newbies 10,686 discussions
Computer Help 54,365 discussions
Laptops 21,181 discussions
Networking & Wireless 16,313 discussions
Phones 17,137 discussions
Security 31,287 discussions
TVs & Home Theaters 22,101 discussions
Windows 7 8,164 discussions
Windows 10 2,657 discussions


Help, my PC with Windows 10 won't shut down properly

Since upgrading to Windows 10 my computer won't shut down properly. I use the menu button shutdown and the screen goes blank, but the system does not fully shut down. The only way to get it to shut down is to hold the physical power button down till it shuts down. Any suggestions?