I am using the following batch file to run my robocopy command:

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:

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):

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"
  • As I said in my answer on the question you link. A file skipped because it's the same is not a failure. Files listed in the log with no action beside them are the ones that were not copied (ie Skipped) because they are the same. Actual failures should be obvious as day. What makes you think you're actually experiencing a failure? Also keep in mind /XO is an exclusion of older files, so while they may seem to be "skipped", they won't be logged because they are not actually skipped, but instead excluded (completely) from processing - no processing = noting to log. – Ƭᴇcʜιᴇ007 Oct 28 '15 at 13:34
  • 1
    Perhaps edit your question and post an excerpt of your log file so we can see what you're experiencing, and give an example of what you expect to see that you are not. – Ƭᴇcʜιᴇ007 Oct 28 '15 at 13:38
  • 1
    /r:1000 gives me no sense in log file. Use /r:0 to make easy subsequent investigation of incidental errors and their cause. – JosefZ Oct 28 '15 at 16:20
  • I would still like to keep r:10 in case of loss of connectivity for a while... and yes r:1000 doesn't make sense.... my mistake – Yash Saraiya Oct 29 '15 at 4:43

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 instance
      2015/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.
  • (cosmetic bug) /w:10 seems to be superabundant in case of /r:0.

The code:

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"
  • I tried your code and it is showing me an error "FINDSTR: Cannot open D:\HAL\log\ErrorLog_20151029_1035.log" – Yash Saraiya Oct 29 '15 at 5:20
  • I guess I have to name the log file exactly as what I used for displaying other details? – Yash Saraiya Oct 29 '15 at 5:51
  • Yep... I named my log file incorrectly for exit code. Thanks. – Yash Saraiya Oct 29 '15 at 5:56
  • What I observed while running your code is that the exit code is logging the errors on console and not in log file. Error's when the robocopy command is running is logged though – Yash Saraiya Oct 29 '15 at 6:08
  • Could you please check this link superuser.com/questions/1104796/… and let me know if you have an answer for this ? – Yash Saraiya Jul 25 '16 at 10:05

According to this article, you may want to try the /v option.

(...) Produces verbose output, and shows all skipped files.

  • I am testing it using /V But how do I log the failed files as well? – Yash Saraiya Oct 28 '15 at 12:22
  • 2
    @YashSaraiya If you tested with /v you should include that information in your question (including results) so we're not suggesting things you've already tried. – Ƭᴇcʜιᴇ007 Oct 28 '15 at 13:32
  • included the result using /v – Yash Saraiya Oct 28 '15 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.