Forgive me ignorance here. I'm very new to writing batch files.
I am copying files from one mapped server drive to a different mapped server drive, and creating a log file after the copy is complete.
My script is below.
@echo off
copy /V "\\server_A\source\%date:~4,2%-%date:~7,2%-%date:~10,4%\*.txt" "\\server_B\destination\" >> "\\server_B\Logs\log_%date:~4,2%-%date:~7,2%-%date:~10,4%.txt"
if %errorlevel% NEQ 0 goto ERROR
echo Copied file successfully >> "\\server_B\Logs\log_%date:~4,2%-%date:~7,2%-%date:~10,4%.txt"
echo The files were copied to destination: \\server_B\destination\ on %Date% at %Time% >> "\\server_B\Logs\log_%date:~4,2%-%date:~7,2%-%date:~10,4%.txt"
goto EOF
:ERROR
echo Copy failed on %Date% %Time% >> "\\server_B\Logs\log_%date:~4,2%-%date:~7,2%-%date:~10,4%.txt"
echo Errorlevel %errorlevel% >> "\\server_B\Logs\log_%date:~4,2%-%date:~7,2%-%date:~10,4%.txt"
goto EOF
:EOF
pause
Currently, the log file works perfectly for success.
However, on a failure (i.e. the dated source folder does not exist), it does not send the "The system cannot find the path specified" message to the log file. Additionally, it still echo's "Errorlevel 1" even though the "system cannot find the path specified" should be errorlevel 3 (as I understand it, anyway).
Any help would be appreciated!