How to get ROBOCOPY to throw an error when there's denied access

1

I am using ROBOCOPY to copy some files from folder A to folder B. I have purposefully made folder B inaccessible using NTFS permission to throw an error so that it can take a different action when copy is failed. However it seems that ROBOCOPY is not throwing a errorlevel that is above 0 or 1 (Success). Using Server 2016 with admin level CMD.

Script that I am using:

@echo on

:: Robocopy's Variables
set source=\\computer1\folder1\
set destination=\\computer2\folder2\
set logfilelocation=C:\scriptfolder\log.txt
set scripts=C:\scriptfolder

robocopy %source% %destination% /E /NFL /NDL /NC /NS /NP /W:1 /R:0 /LOG:%logfilelocation%
if ERRORLEVEL 1 goto success
if ERRORLEVEL 0 goto success

:FAIL
call %scripts%\failed.bat
goto end

:SUCCESS
call %scripts%\success.bat

:END

So basically, if I run echo %errorlevel% after the robocopy line, it throws a errorlevel of 0 (success) while the log shows access denied for all files.

2018/08/27 10:22:52 ERROR 5 (0x00000005) Accessing Destination Directory \\computer2\folder2\
Access is denied.

I wanted an error, but just not giving me ROBOCOPY errorlevel higher than 1. Any suggestions so I can take action when the files do not copy?

robocopy
asked on Super User Aug 27, 2018 by JuniorPenguin

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0