![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Compare-Object and Get the name of object/File? I want to compare two directories and copy the files that are not in directory $A to directory $B. My initial try to see what I get back: $A = Get-ChildItem -path C:\test1 $B = Get-ChildItem -path C:\test2 $C = Compare-Object $A $B ForEach ($f in $C) { Write-Host $f } It Spit back this: @{InputObject=test.txt; SideIndicator=<=} @{InputObject=test2.txt; SideIndicator=<=} @{InputObject=test3.zip; SideIndicator=<=} @{InputObject=test4.txt; SideIndicator=<=} How would I got about extracting the fullnames for each of those files? After that I can pass it to a function for work to be done. |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Compare-Object and Get the name of object/File? akcorr wrote: Quote: > I want to compare two directories and copy the files that are not in > directory $A to directory $B. My initial try to see what I get back: > > $A = Get-ChildItem -path C:\test1 > $B = Get-ChildItem -path C:\test2 > > $C = Compare-Object $A $B Quote: > How would I got about extracting the fullnames for each of those files? > After that I can pass it to a function for work to be done. PS > $C|ForEach-Object{$_.InputObject}|ForEach-Object{$_.FullName} C:\test2\bar.txt C:\test1\foo.txt PS > That could also be more simply: $C|ForEach-Object{($_.InputObject).FullName} Hope that helps... Marco -- Microsoft MVP - Windows PowerShell http://www.microsoft.com/mvp PowerGadgets MVP http://www.powergadgets.com/mvp Blog: http://marcoshaw.blogspot.com |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Compare-Object and Get the name of object/File? 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 Specs![]() |
| | #4 (permalink) |
| | 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. 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 Specs![]() |
| | #5 (permalink) |
| | Re: Compare-Object and Get the name of object/File? Definitely! -- Shay Levi $cript Fanatic http://scriptolog.blogspot.com a>> I want to compare two directories and copy the files that are not in a>> Quote: Quote: >> a> directory $A to directory $B. >> o> o> copy c:\test1\*.* c:\test2 -Exclude (dir c:\test2) -WhatIf o> o> Greetings /\/\o\/\/ o> o> "Shay Levi" wrote: o> Quote: 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 Specs![]() |
| | #6 (permalink) |
| | Re: Compare-Object and Get the name of object/File? On Tue, 17 Jun 2008 06:24:01 -0700, /\/\o\/\/ [MVP] <oMVP@xxxxxx> wrote: Quote: >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\/\/ > robocopy c:\test1 c:\test2 /l Remove /l to actually copy the files.... :-) |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| compare-object | PowerShell | |||
| Formating with Compare-Object | PowerShell | |||
| compare object | PowerShell | |||
| Testing object arrays using Compare-Object and -contains | PowerShell | |||
| Adding canonical aliases for Compare-Object, Measure-Object, New-Object | PowerShell | |||