Question : Batch file to copy and verify

I need to write a batch file that will be scheduled nightly to copy some local files to a network drive.

I want to be thorough and be certain the files got copied and log either success or failure.

I'm planning to use:
copy "c:\source\*.*" \\server\share\mydestination" /v

It seems there are three ways this can fail.  The source is not available, the destination is not reachable, or the verification fails.

Is there anyway to tell the difference? Does copy return a different error level depending on the failure or is it just errorlevel = 0 or errorlevel = 1?

Thanks.


Answer : Batch file to copy and verify

Why not check the conditions separately?

So, something like this:

if not exist "c:\source\*.*" (
  echo Source not found.
  exit /b
)
if not exist " \\server\share\mydestination\" (
  echo Destination not found.
  exit /b
)
copy "c:\source\*.*" \\server\share\mydestination" /v
if errorlevel 1 (
  echo Errors in copy / verify
  exit /b
)

~bp
Random Solutions  
 
programming4us programming4us