[<<]Message[>>]    [<<]Author[>>]    [<<]Subject[>>]    [<<]Thread[>>]

Number : 4406 Date : 2003-04-22 Author : Garry Deane Subject : Re: errorlevel Size(KB) : 1
--- 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.