-3

I need to get the number of files which I moved with robocopy. I've tried a lot of methods, but I need exactly the number which I see in the cmd line after robocopy has finished the process and shows me the result.

Copied files - x

How can I get the value of x? Thanks in advance.

Sam Denty
  • 3,693
  • 3
  • 30
  • 43

2 Answers2

2
robocopy [Whatever Options] | findstr "Copied files"

will get you down to just the final report.

You just need to parse out for the actual number, which you can do with a for loop.

I would help you more, but you did not show any code.


When I run robocopy, the output I get looks like:

              Total    Copied   Skipped  Mismatch    FAILED    Extras
   Dirs :         1         0         1         0         0         0
  Files :        12        12         0         0         0         0
  Bytes :   49.91 m   49.91 m         0         0         0         0
  Times :   0:00:00   0:00:00                       0:00:00   0:00:00

This is very different from your report that you see Copied Files - X.


I think this is getting close to what you want:

setlocal enabledelayedexpansion

for /f "tokens=3 delims=: " %%a in ('robocopy [options] ^| findstr /C:Files ') do (
    set num=%%a )

echo Files That Got Copied: %num%

(lightly tested, it seems to work)

abelenky
  • 63,815
  • 23
  • 109
  • 159
  • Thanks for the reply.If I got correctly It is possible to use findstr just to search in files, so I have to write a log file with robocopy's report firstly and then try to find my phrase there. Is that right? Which code would you like to see? I have just string with robocopy. – Roman Kovalchik Feb 27 '17 at 14:35
  • I just ran Robocopy on my machine, and it does **not** include the output `Copied files - X`. What options are you passing to robocopy? What exact output are you seeing? – abelenky Feb 27 '17 at 17:15
  • I get the same, but in Russian. Sorry for that. So I need to get the number 12 in your case, files which are copied. Setlocal enabledelayedextantion robocopy [options]| for /f "tokens=4 delims=....... " %%a in ('findstr /I "Files" ) do set num=%%a echo !num! I see in cmd set num=12 but actually it doesn't change when i use it after. Thanks. – Roman Kovalchik Feb 27 '17 at 18:33
  • Do not post code in comments. That is very difficult to read. Edit your answer to include your code. – abelenky Feb 27 '17 at 18:58
0

If you want to create a log then you have to use the /log option. Otherwise, you can see the number of your copied files as long as you do NOT use the /njs option.

for /f "tokens=3 skip=1" %%a in (
 'robocopy /L . " nothing ..//" ^|findstr /rc:":  *[0-9][0-9]* "'
)do echo %%a
pieh-ejdsch
  • 206
  • 1
  • 6
  • Sorry but I still can't get the idea. Your code returns me echo ':'. Moreover I haven't got how robocopy can work in cycle for. I want to move files with robocopy (pretty easy) and then write the number of copied files in the variable. This number I have to get from robocopy's report. Sry for no code. I am forced to use my smartphone – Roman Kovalchik Feb 28 '17 at 13:04