05 Mar 2009 11:55
joker197cinque
I'm looking for a way to parse robocopy output log to find number of copied files and to pass it as a variable to another program....
Can you point me in right direction ?
Thanks.
F.
----------------------------
#2 05 Mar 2009 12:56
bluesxman
Something like this, perhaps?
* * * UNTESTED * * *
@echo off
setlocal
REM drop a robocopy log file containing only the job summary.
robocopy "x:\source directory" "y:\target directory" /njh /ndl /ndl /log:"yourLogfile.txt"
REM parse the line in that log containing "Files :" and pull the Copied count out.
for /f "usebackq tokens=3 delims=: " %%a in (`type "yourLogFile.txt" ^| find "Files :"`) do set files.copied=%%a
endlocal & exit /b %files.copied%
This should set the errorlevel generated by the script as the number of files copied.
cmd | *sh | ruby | chef
----------------------------
#3 05 Mar 2009 13:29
joker197cinque
Hi bluesxman and thanks for reply.
The robocopy instructions I have to use is:
robocopy source destination /R:0 /MIR >log.txt
Can I add /njh /ndl /ndl switches safely ?
I tried to run this script replacing proper parts but ... ehm ... where is the final variable ? smile
I tried to echo %files.copied% after the code below but the shell does not show anything.
for /f "usebackq tokens=3 delims=: " %%a in (`type "yourLogFile.txt" ^| find "Files :"`) do set files.copied=%%a
endlocal & exit /b %files.copied%
Can you please please explain in detail what exactly does this piece of script ? I'll surely learn a lot from you.
Thanks for help.
----------------------------
#4 05 Mar 2009 13:36
joker197cinque
Sorry, bluesxman, my fault.
It works like a charm!!!
If you want, I'll be so grateful if you want to explain how it works.
Thanks.
----------------------------
#5 05 Mar 2009 13:45
joker197cinque
Here is my final script, I have a problem ...
@echo off
setlocal
robocopy "C:\inetpub\wwwroot\wm" "U:\Msync\wm" /R:0 /MIR /njh /ndl /ndl /log:log.txt
for /f "usebackq tokens=3 delims=: " %%a in (`type "log.txt" ^| find "Files :"`) do set files.copied=%%a
if not %files.copied% == 0 "C:\balloon.exe" %files.copied%
endlocal & exit /b %files.copied%
The problem is that when balloon.exe is executed, the shell does not quit until the balloon.exe is closed.
Is there a workaround for this ?
Thanks.
----------------------------
#6 05 Mar 2009 14:41
bluesxman
It looks at the output produced by the robocopy command (type "yourLogFile.txt"), filters out the line containing the file count (^| find "Files :") and takes the 3rd non-blank column (tokens=3) of data, delimited by ":" and " " (delims=: ).
The exit /b %files.copied% bit is what sets the exit code for the script.
Try using:
start "" "C:\balloon.exe" %files.copied%
to prevent the script from waiting for "balloon.exe" to finish.
Last edited by bluesxman (05 Mar 2009 15:33)
Parse Robocopy log to find copied files
- MigrationUser
- Posts: 336
- Joined: 2021-Jul-12, 1:37 pm
- Contact: