On Oct 12, 12:17 am, hrh1818 <hr...@xxxxxx> wrote:
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
Howard,
I've done it in the past with foreach loops.
[6] » $a = 'file1', 'file2', 'file3'
[7] » $b = 'file2', 'file3', 'file4'
[8] » foreach ($i in $a){If($b -notcontains $i){$i}}
file1
[9] » foreach ($i in $b){If($a -notcontains $i){$i}}
file4
There's probably a better way to do it, but it doesn't come to mind at
the moment.
Kuma