computing
  • 0

Need ErrorLevel Help In XCopy Batch File.

  • 0

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

:Error
echo The Archive Drive is FULL! STOPPING Backup Procedure.
Exit
_______________________

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

Share

1 Answer

  1. Truthfully, I have never heard of the errorlevel going 0,1,2,4,5. The most errors I have ever had in a program is 1. What I think you need to try is a success/fail setup. Basically, replace your if errorlevel lines with this:

    if errorlevel 1 goto failure
    if errorlevel 0 goto success

    Then have failure setup as:

    :FAILURE
    CLS
    ECHO Backup has failed! Please see XCOPY.LOG.
    GOTO END

    I added the sentence “Please see XCOPY.LOG.” for a reason. If you still wanted to know what the errors were, you can setup the XCOPY command like this:

    xcopy i:\*.* h:\archive\graphics\%INPUT% /D/E/R/I/K/-Y/exclude:i:\ErrorMssg\omit.txt > XCOPY.LOG

    What the extra code will do is create a file showing what would appear on the screen when executing the XCOPY command, including the errors, in the directory the batch file is located. I created a little remap of the entire code from post #10. Take a look:

    @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/exclude:i:\ErrorMssg\omit.txt > XCOPY.LOG

    if errorlevel 1 goto failure
    if errorlevel 0 goto success

    :FAILURE
    CLS
    ECHO Backup has failed! Please see XCOPY.LOG.
    GOTO END

    :success
    echo y | rd /s/q i:\DailyWork
    echo y | del i:\Clients.xls
    echo The backup was successful.
    goto end

    :end
    pause
    exit

    Perhaps try it out and see if you like it?

    Mouse could not be found. Click OK to continue.
    What to do now?

    • 0