RoboCopy Log File Analysis

1

Is it possible to analyse the log text file outputted from RoboCopy and extract the lines which are defined as "New Dir" and "Extra Dir"?

I would like the line from the log contain all the details returned regarding this "New Dir" or "Extra Dir"

The reason for completing this task is to understand how two folder structures have change over time. One version has been kept internally at the parent company, the second has been used by a consultancy.

For your information I am using Windows 7.

BobJim

Posted 2013-10-24T15:48:11.770

Reputation: 980

Answers

1

Use the following PowerShell string:

Get-ChildItem C:\robocopy-log.txt | Select-String -Pattern '(New Dir)|(Extra Dir)'


To filter out the filename and line numbers use:

Get-ChildItem C:\robocopy-log.txt | Select-String -Pattern '(New Dir)|(Extra Dir)' | ForEach-Object {$_.Line}

Josh

Posted 2013-10-24T15:48:11.770

Reputation: 4 746

The code appears to run and returns immediately back to the original drive letter H:>? Do i need some extra code to write the output to a separate text file? – BobJim – 2013-10-25T14:21:16.830

@BobJim Yes. Just redirect the output to file like so: Get-ChildItem C:\robocopy-log.txt | Select-String -Pattern '(New Dir)|(Extra Dir)' > results.txt – Josh – 2013-10-25T14:38:33.260

I had been trying to use '| Get-Process | Out-File C:\results.txt.' My method appears to be far more complicated. Using your method, it does produce a text file but it's blank??? – BobJim – 2013-10-25T15:13:03.877

Do the strings that are in the -Pattern section of Select-String actually exist in the text file? Does New Dir appear in the file when you open it up? Post a sample line from your log file that you want to single out. – Josh – 2013-10-25T17:27:32.523

New Dir 2 R:\A_Folder\Folder_1\Folder_2\Folder_3\The_New_Folder\ – BobJim – 2013-10-28T08:59:18.980

*EXTRA Dir -1 E:\A Folder\Folder_1\Folder_2\Folder_3\The_EXTRA_Dir\ – BobJim – 2013-10-28T09:00:33.767

1Using the code I posted and a sample text file I'm able to filter out the appropriate lines. Have you tried running the command in the PowerShell command prompt to see what results you get? – Josh – 2013-10-28T14:16:44.037

Thanks Josh, this code is now working. Is it possible to only the include the text from the robocopy log but exclude the preceding information regarding identifying which file was searched and which line the information appeared on? – BobJim – 2013-10-29T08:16:08.727

1Try Get-ChildItem C:\robocopy-log.txt | Select-String -Pattern '(New Dir)|(Extra Dir)' | ForEach-Object {$_.Line} to filter out the filename and line numbers. – Josh – 2013-10-29T13:58:52.830