View Single Post
Old 10-11-2007   #6 (permalink)
hrh1818


 
 

Re: Creating a list of files that have been deleted from or added to a directory

On Oct 11, 10:30 am, Shay Levi <n...@xxxxxx> wrote:
Quote:

> Try the Compare-Object cmdlet
>
> Compare-Object $a $b
>
> PS C:\Scripts> $a = 'file1', 'file2', 'file3'
> PS C:\Scripts> $b = 'file2', 'file3', 'file4'
> PS C:\Scripts> Compare-Object $a $b
>
> InputObject SideIndicator
> ----------- -------------
> file4 =>
> file1 <=
>
> For further help type
>
> help Compare-Object -full
>
> Shayhttp://scriptolog.blogspot.com
>
Shay, Thank you for your reply.
Compare-object works perfectly with directory listings. But it
produces a different output than Ruby's Array difference when there
are duplicate items in an array. PowerShell produces the following
output with duplicate items.

$a = 1, 1, 2, 2, 3, 3, 4, 5
$b = 1, 2, 4
compare-object $a $b

InputObject SideIndicator
----------- -------------
1 <=
2 <=
3 <=
3 <=
5 <=

Where as Ruby produces the following output with duplicate items.

irb(main):001:0> a = [1, 1, 2, 2, 3, 3, 4, 5]
=> [1, 1, 2, 2, 3, 3, 4, 5]
irb(main):002:0> b = [1, 2, 4]
=> [1, 2, 4]
irb(main):003:0> a - b
=> [3, 3, 5]

Hence I conclude Powershell"s compare-object is not an exact
equivalent for Ruby's array Difference.

Howard




My System SpecsSystem Spec