Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove percentages from robocopy log

I'm using an older version of robocopy that includes percentages in the log even if the /NJH and /NJS paramters are set. So I'd like to remove the percentages from the log:

            72880735    H:\1.txt
100%  
            33038490    H:\10.txt
100%  
            64878348    H:\2.txt
100%  
            25875810    H:\3.txt
  0%  
100%  

I've tried with

(Get-Content $logfile) | Where-Object {
    $_ -match '[\s](\d{1,})(\s+)(\w\W\W.+)'
} | Set-Content $logfile

But that results in

            72880735    H:\1.txt
            33038490    H:\10.txt 
            64878348    H:\2.txt
            25875810    H:\3.txt
  0%  

So I get the 100%'s stripped out, but not the 0%.

like image 594
RMK Avatar asked Jul 12 '17 23:07

RMK


People also ask

How do I show percentage complete in robocopy?

the default behavior of robocopy is to include percentages. Use /np to not include progress. it indicate the per-file percentage, not a percentage for the whole job.

What does * Extra file mean in robocopy?

Extra files simply mean there are files in the destination that are not in the source. If you'd use /mir it would delete the extra files (not what you want!).

Does Robocopy log?

Robocopy does not keep a default log file. It does however only copy files with differences by default. So if you tried the same copy again it would skip the ones that had already successfully copied.

Does robocopy create a log file?

Creates a log file containing the output of the robocopy job. output status to LOG file (append to existing log). Instead of overwriting the preview log, the output will be added to an already existing log. output status to LOG file as UNICODE (overwrite existing log).


1 Answers

/njh and /njs have nothing to do with the percentage information. You need to suppress progress output by adding the option /np to your robocopy commandline.

From the documentation:

/np Specifies that the progress of the copying operation (the number of files or directories copied so far) will not be displayed.


Edit: After taking a look at your actual commandline it looks like /np is not compatible with /mt. Adding the latter parameter makes robocopy display progress output even if /np is present. If you don't require running multi-threaded I'd remove that parameter (add /ndl to prevent directories from appearing in the output).

I would also recommend using splatting instead of putting the parameter list into a single string:

$params = $src, $dest, ('/LOG:"{0}"' -f $logpath), '/L', '/NP', '/NC', '/BYTES',
          '/NJH', '/NJS', '/NDL', '/E', '/MOVE', '/XC', '/XN', '/XO', '/XD',
          $excludedFoldersList

& robocopy @params

If for some reason you must use multi-threading you should be able to remove progress information from the log after completion like this:

(Get-Content $logpath) | Where-Object {
    $_ -notmatch '^\s*\d{1,3}%\s*$'
} | Set-Content $logpath
like image 74
Ansgar Wiechers Avatar answered Oct 03 '22 21:10

Ansgar Wiechers