Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: xcopy error routine  (Read 5655 times)

0 Members and 1 Guest are viewing this topic.

PETEMAFL

  • Guest
xcopy error routine
« 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.


Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: xcopy error routine
« Reply #1 on: June 14, 2005, 06:37:08 AM »
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
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

PETEMAFL

  • Guest
Re: xcopy error routine
« Reply #2 on: June 14, 2005, 07:28:06 AM »
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:

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: xcopy error routine
« Reply #3 on: June 14, 2005, 08:07:49 AM »
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)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein