Computer Hope
Microsoft => Microsoft DOS => Topic started by: PETEMAFL on June 14, 2005, 06:24:30 AM
-
I am trying to add an error routine for using xcopy in a batch file using windowsXP & 2000 at the command prompt
ex..
if (error) goto err
xcopy x y
goto ok
err:
echo problem etc.
-
These are the errorlevel codes that XCOPY generates:
0 Files were copied without error.
1 No files were found to copy.
2 The user pressed CTRL+C to terminate xcopy.
4 Initialization error occurred. There is not enough memory or disk space, or you entered an invalid drive name or invalid syntax on the command line.
5 Disk write error occurred.
Good luck. 8)
PS. Wouldn't you want to check the error codes after XCOPY? .... just asking :D
-
This is what I am doing..havn't used bat files or DOS in quite awhile. The log file gets created ok, but it just dies with 0 files
Xcopy /s/i/v/d/r/Y "c:\Documents and settings\Anna\my documents" "P:\My Documents" >> c:\bu-key.log
if errorlevel =2 goto Prob
if errorlevel =4 goto Prob
if errorlevel =5 goto Prob
cls
goto ok
Prob:
echo Xcopy had a problem....Notify Anna at ext .... for Help
echo We had a Problem >> c:\bu-key.log
pause
goto end:
ok:
echo Back-up of Key Files to Server Complete
echo Back-up ....ok >> c:\bu-key.log
end:
-
Errorlevel checking is not what it seems. The comparision is actually equal to or greater than. With this in mind, reverse your error checks and lose the equal signs.
if errorlevel 5 goto Prob
if errorlevel 4 goto Prob
if errorlevel 2 goto Prob
In your case, all you need is a check for errorlevel 1 which covers 1, 2, 3, 4, and 5, but this become problematic if each errorlevel goes to a different label.
Hope this helps. 8)