Given the following sample code (Powershell), which is based on this solution:
$newFiles = @(Get-ChildItem -recurse -path "c:\path1");
$oldFiles = @(Get-ChildItem -recurse -path "c:\path2");
Compare-Object -ReferenceObject $newFiles -DifferenceObject $oldFiles -Property FullName,Length,LastWriteTime
I have SideIndicator to tell whether or not an object with the same property set is present in either sides. But this is usually of little use for production purposes. What I really need is key all objects by FullName and then compare by Length and LastWriteTime (for the above example). If different, be able to tell what exactly is different (Length or LastWriteTime or both), and how exactly (>, <, =). Is it possible with Powershell, using built-in ways?
Compare-Objectis a pretty feature-light cmdlet. It could stand some serious improvements. The best way I could get this to work was to piece out the removed/added files into a separate bucket and then compare just the same files usingNamenotFullNamewith aSyncWindowof 1 e.g.:This gave me results like this:
Even so, part way through the listing the files get out of sync. Go figure. If you eliminate the SyncWindow parameter, you still get “correct” results it is just that the files are scattered about and not lined up one under another. 🙁