Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looking for a PowerShell script to compare two folders recursively

Tags:

powershell

Just thought it would be nice to have one but my PS skills are not up to task. Anybody can share theirs?

like image 952
Sergey Aldoukhov Avatar asked Sep 29 '09 16:09

Sergey Aldoukhov


People also ask

How do I compare two folders for differences?

If you double-click on a folder, it will expand to reveal its contents. If you double-click on a file it will open a side by side comparison and will highlight the differences, if any, between the two files. Double-clicking a file will open both copies in a side by side view and will highlight any differences.

How do you compare two folders and copy missing files?

WinMergeDownload and open WinMerge. In the File tab > click Open. Browse for the folders you want to compare. Click Compare.

How do I compare two arrays in PowerShell?

You can also use PowerShell to compare arrays using the Compare-Object cmdlet. This cmdlet takes a reference object and a difference object and returns a side indicator indicating which elements are and are not in either array. You can see below that the Compare-Object cmdlet allows you to compare both arrays at once.


1 Answers

Easy enough to do something simple:

$d1 = get-childitem -path $dir1 -recurse
$d2 = get-childitem -path $dir2 -recurse
compare-object $d1 $d2

More sophistication required depending on the definition of difference.

like image 111
Richard Avatar answered Oct 08 '22 18:10

Richard