View Single Post
Old 10-11-2007   #4 (permalink)
Shay Levi


 
 

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


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


Shay
http://scriptolog.blogspot.com


Quote:

> In Powershell if I have the following two arrays:
> $a = 'file1', 'file2', 'file3'
> $b = 'file2', 'file3', 'file4'
> The operation $a - $b produces a method not implemented error.
> Whereas in Ruby if I have the following two arrays:
> a = ['file1', 'file2', 'file3']
> b = ['file2', 'file3', 'file4']
> The operation a - b produces the output ["file1"]
> and the operation b - a produces the output ["file4"]
> This use of the subtraction operator in Ruby is very useful when
> creating a list of files that have been deleted or added to a
> directory. What method in Powershell will produce the same results as
> a - b does with arrays in Ruby?
>
> Howard
>

My System SpecsSystem Spec