|
|
||||||
|
#1
|
|
|
|
|
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. |
|
|
|
#2
|
|
|
|
|
akcorr wrote:
> 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 > 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. I'd skip the foreach loop: 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 |
|
#3
|
|
|
|
|
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/ |
|
#4
|
|
|
|
|
a> I want to compare two directories and copy the files that are not in
> 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: [..] |
|
#5
|
|
|
|
|
Definitely!
|
|
#6
|
|
|
|
|
On Tue, 17 Jun 2008 06:24:01 -0700, /\/\o\/\/ [MVP]
<oMVP> wrote: >a> I want to compare two directories and copy the files that are not in >> 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\/\/ > To list the files that would be copied: robocopy c:\test1 c:\test2 /l Remove /l to actually copy the files.... :-) |
|
|
| Similar Threads | |
| Thread | Thread Starter |
| Convert File Object into Class Object is there any way to convert a java object of type File to type Class? my problem is that want to scan a directory and find files that ends with ".class" and treat them as... |
Aned |
| Testing object arrays using Compare-Object and -contains I'm having trouble finding a simple scheme for getting all objects which are members of a set B but not also members of another set A. The specific real problem is a tool... |
Alex K. Angelopoulos [MVP] |
| Object creation - Do we really need to create a parent for a derieved object - can't the base object just point to an already created base object OK! I had this nagging doubt Consider (without worrying abt access specifiers) class Kid : public Parent{...}; Parent::someFunc() { Kid k; } |
jon wayne |
| PowerPoint VBA - Picture Object, OLE Object file extension, type, or format I am writing an add-in that loops through a PowerPoint application and exports all the included images. The problem is when I export the image I need to specify a format... |
AD |
| Problem : To link a .cpp main file with a C object(.o) and C++ object(.o) using xlc compiler We are trying to link a .cpp main file with a C object(.o) and C++ object(.o) using xlC compiler on IBM-AIX. Please let us know, if anyone has a solution to this problem... |
GyungChan |
|
Privacy Policy | All times are GMT. The time now is 12:36 PM.
|
|
|