View Single Post
Old 06-17-2008   #4 (permalink)
/\/\o\/\/ [MVP]


 
 

Re: Compare-Object and Get the name of object/File?

a> I want to compare two directories and copy the files that are not in
Quote:

> a> directory $A to directory $B.
Another way to do this from PowerShell that might be interesting :

copy c:\test1\*.* c:\test2 -Exclude (dir c:\test2) -WhatIf

Greetings /\/\o\/\/

"Shay Levi" wrote:
Quote:

> Hi akcorr,
>
> compare-Object $A $B | select InputObject
>
> Make sure to read Dmitry's post on the -syncWindow parameter:
> http://dmitrysotnikov.wordpress.com/...object-gotcha/
>
>
>
> ---
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
>
> a> I want to compare two directories and copy the files that are not in
> a> directory $A to directory $B. My initial try to see what I get back:
> a>
> a> $A = Get-ChildItem -path C:\test1
> a> $B = Get-ChildItem -path C:\test2
> a> $C = Compare-Object $A $B
> a>
> a> ForEach ($f in $C)
> a> {
> a> Write-Host $f
> a> }
> a> It Spit back this:
> a>
> a> @{InputObject=test.txt; SideIndicator=<=}
> a> @{InputObject=test2.txt; SideIndicator=<=}
> a> @{InputObject=test3.zip; SideIndicator=<=}
> a> @{InputObject=test4.txt; SideIndicator=<=}
> a> How would I got about extracting the fullnames for each of those
> a> files? After that I can pass it to a function for work to be done.
> a>
>
>
>
My System SpecsSystem Spec