-1

I use robocopy in order to move files from the source to the target folder. That works well, I'm a bit surprised about the logging of robocopy - it lists all files of the target folder?

Lets say we have two folders, an empty source folder and a target folder with some files (target1-3). If I run this command:

robocopy "D:\test\source" "D:\test\target" /S /MOV /R:10 /W:30 /UNILOG+:"log.txt"

I got this output (sorry für the german):

-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robustes Dateikopieren fr Windows                              
-------------------------------------------------------------------------------

  Gestartet: Dienstag, 6. April 2021 20:50:24
   Quelle : D:\test\source\
     Ziel : D:\test\target\

    Dateien : *.*
        
  Optionen: *.* /S /DCOPY:DA /COPY:DAT /MOV /R:10 /W:30 

------------------------------------------------------------------------------

                       0    D:\test\source\
      *EXTRA Datei             0    target1.txt
      *EXTRA Datei             0    target2.txt
      *EXTRA Datei             0    target3.txt

------------------------------------------------------------------------------

           Insgesamt   KopiertšbersprungenKeine šbereinstimmung    FEHLER    Extras
Verzeich.:         1         0         1         0         0         0
  Dateien:         0         0         0         0         0         3
    Bytes:         0         0         0         0         0         0
   Zeiten:   0:00:00   0:00:00                       0:00:00   0:00:00
   Beendet: Dienstag, 6. April 2021 20:50:24

Why does robocopy list all files from the target folder? How could I avoid that? (This list could become long in the real use case.)

Mike969
  • 39
  • 6

1 Answers1

1

You can use additional switches to reduce the logging. I recommend having a look at the documentation of robocopy. You can add the /NFL option to omit the logging of files. And you can add the /NDL option to omit the logging of directories:

robocopy "D:\test\source" "D:\test\target" /S /MOV /R:10 /W:30 /NFL /NDL /UNILOG+:"log.txt"

But this will omit the logging of all files and directories (not only the EXTRA ones). If you just do not want to have EXTRA files and directories in your log, but everything else, you need additional tools. You can post process your log file (if it is worth it):

(Select-String -Path log.txt -Pattern '^\s+\*EXTRA' -NotMatch | Select-Object -ExpandProperty Line) | Set-Content -Path log.txt

This PowerShell pipeline will remove every line from log.txt, that starts with spaces, followed by *EXTRA.

FYI: robocopy logs EXTRA files, because it cannot only be used for copying, but also for a unidirectional synchronization. So you cannot only copy files to a destination, but also delete files at a destination, that do not exist (anymore) at the source location. Have a look at the /PURGE and /MIR options.

stackprotector
  • 10,498
  • 4
  • 35
  • 64
  • Ok, so robocopy doesn't make a difference in logging depending on the requested action. Then it remains with the additional entries in the log. – Mike969 Apr 14 '21 at 20:27
  • Basically, the action is always a unidirectional synchronization, you just decide if you want to *keep* extra files or not. You can even sync an empty source to a destination while using the `/PURGE` option. This will make `robocopy` look like a delete operation. So the word "copy" in "robocopy" might somehow be misleading. – stackprotector Apr 15 '21 at 05:30