![]()
[<<]Message[>>] [<<]Author [<<]Subject[>>] [<<]Thread[>>]
Number : 4411 Date : 2003-04-22 Author : jtv1966 Subject : Re: errorlevel Size(KB) : 2
Hi Garry, I tried your code & still get the wrong exit code for xcopy. When I xcopy a dir that doesn't exist the errorlevel return a 0 within the script but if you do it interactively at c:\ it returns a 4. I don't think errorlevel is holding the exit code after the xcopy. Let me know if you have any more suggestions. Thanks John. --- In xxcopy@yahoogroups.com, "garrydeane" wrote: > --- In xxcopy@yahoogroups.com, "jtv1966" wrote: > > I am having problem getting xxcopy, xcopy or robocopy > > to return correct errorlevel so my scripts can determine > > if the copy operation was successful. The errorlevel > > return 0 even when the file was not found to copy. > > Please advice & thanks in advance for your assistance. > > > > cls > > echo off > > if exist c:\scripts\archiveerr.log del archiveerr.log > > if exist c:\scripts\archivesuccess.log del archivesuccess.log > > for /f %%i in (%1) do ( > > xxcopy %%i c:\arcto%%i /E /V /H /I /Y /R > > if errorlevel 0 ( > > Echo Copied successfully %%i >>archivesuccess.log > > rd %%i /s /q > > if not exist %%i Echo removed directory %%i > > >>archivesuccess.log > > ) else ( > > Echo Error occured for %%i >>archiveerr.log > > ) > > ) > > You aren't using the IF ERRORLEVEL test correctly. IF ERRORLEVEL nn > evaluates as true if the errorlevel is equal to OR GREATER THAN > nn. "if errorlevel 0" will always evaluate as true because errorlevel > will always be greater than or equal to 0. > > The usual way to carry out the above is to test in the negative. > if not errorlevel 1 ( > Echo Copied successfully %%i >>archivesuccess.log > ) else ( > Echo Error occured for %%i >>archiveerr.log > ) > > Since you're using NT or above, you can also do this: > if %errorlevel% EQU 0 ( > Echo Copied successfully %%i >>archivesuccess.log > ) else ( > Echo Error occured for %%i >>archiveerr.log > ) > > Also, you need to be aware that Xxcopy sets the errorlevel to 100 if > no files were found to copy and to 100+no_of_failed_copies if the > copy succeeded but there were some failed copies. > > You can either use the /ER switch to change the error codes to be > xcopy compatible (see XXTB #31) or also test for the errorlevel 100 > case (see XXTB #19). You might write your test like the following: > > if %errorlevel% NEQ 0 if %errorlevel% NEQ 100 ( > Echo Error occured for %%i >>archiveerr.log > ) else ( > Echo Copied successfully %%i >>archivesuccess.log > ) > > Garry
This message if part of XXCOPY's message Archive. The archive contains all the messages posted at Yahoo!Groups: XXCOPY.