I am using the following batch file to run my robocopy command:
@ECHO OFF
for /f %%a in ('wmic os get LocalDateTime ^| findstr ^[0-9]') do (set ts=%%a)
robocopy [source] [target] /log+:D:\logs\log_%ts:~0,8%.log /e /xo /w:10 /r:1000 /z /NP
robocopy [source] [target] /log+:D:\logs\log_%ts:~0,8%.log /e /xo /w:10 /r:1000 /z /NP
This helped me log all the details I was looking for except that it did not logged the names of the skipped/failed files. Is there a script/robocopy command/any other way to log the names of the skipped/failed files to help me determine such files. It becomes really difficult to determine such files for a large volume of file transfer over the network.
The closest I came to a similar question is this, but even that didn't had any accepted/working answers
EDIT 1: As per the comment by Kamen Minkov, I included /v (verbose) in my robocopy command). When I purposefully failed the file transfer, it logged the error (retries history), but this makes the log file more and more harder to interpret. The same case was observed even without /v. I just want the failed transfer file name to be logged as failed once in my .txt log file
EDIT 2: As per JosefZ's Answer, I ran the following code:
@ECHO OFF
for /f %%a in ('wmic os get LocalDateTime ^| findstr ^[0-9]') do (set ts=%%a)
robocopy [source] [target] /log+:D:\logs\log_%ts:~0,8%.log /e /xo /w:10 /r:0 /z /NP /V
if errorlevel 8 findstr "^[0-9,a-Z]" "D:\logs\log_%ts:~0,8%.log"
This gave me following error after transferring all the files (I unplugged the network cable to fail a few files, so there were failed files):
FINDSTR: Cannot open D:\ABC\log\ErrorLog_20151029_1035.log
EDIT 3: The above error occurred because I incorrectly mentioned the name of the log file for exit code. The correct code is (As answered by JosefZ):
@ECHO OFF
for /f %%a in ('wmic os get LocalDateTime ^| findstr ^[0-9]') do (set ts=%%a)
robocopy [source] [target] /log+:D:\ABC\log\log_%ts:~0,8%_%ts:~8,4%.log /e /xo /w:10 /r:2 /z /NP /V /TEE
if errorlevel 8 findstr "^[0-9,a-Z]" "D:\ABC\log\log_%ts:~0,8%_%ts:~8,4%.log"
Best Answer
As per
robocopy /?
(or robocopy.exe description) and ROBOCOPY Exit Codes, use:/V
produce Verbose output, showing skipped files;/R:0
(no retry) will speed up copying by skipping any in-use files and reduces description of any incidental particular error in log file to the only occurrence (this makes easier subsequent investigation or error cause);if errorlevel 8 findstr "^[0-9,a-Z]" "D:\logs\log_%ts:~0,8%.log"
explanation:errorlevel
greater than 7 indicates that there was at least one failure during the copy operation;findstr "^[0-9,a-Z]" ...
displays only logged errors, for instance2015/10/28 17:27:55 ERROR 32 (0x00000020) Copying File [source]\file.ext
The process cannot access the file because it is being used by another process.
/w:10
seems to be superabundant in case of/r:0
.The code: