Windows XP Forums


Reply
Thread Tools Display Modes

Powershell to compare to Directory Trees?

 
 
AreWeThereYet
Guest
Posts: n/a
 
      25th November 2007
Just discovered PowerShell. Convenient, since I need it more now than ever
before it seems lately.

Copied a LARGE directory tree across the network. The connection was reset
by peer near the end and I don't know what got left off the boat.

How do I "diff" the two LARGE directory structures and find out which paths
were not copied? If I could then re-copy those paths by script it would be a
bonus, but I won't push my luck.

Local System is XP-Pro SP2
Copying FROM my linux box.



 
Reply With Quote
 
 
 
 
Shay Levi
Guest
Posts: n/a
 
      25th November 2007

Here's a sample Powershell script

$source="C:\Backup"
$destination="D:\temp\backup"

get-childitem -path $source -recurse | where {!$_.PSIsContainer}
foreach {
$path=$destination+$_.fullname.remove(0,$source.le ngth)

# test if the file already exist on destination direcotry
if(test-path $path -pathtype leaf){

# if the file sizes are not equal copy the file again - overwrite
if($_.length -ne (get-childitem $path).length){
write-host "files $($_.name) length dont match"
copy-item $_.fullname -destination $path
}
} else {
write-host "the file $($_.name) doesn't exist, copy to destination"
copy-item $_.fullname -destination $path -force
}



--
Shay Lev
-----------------------------------------------------------------------
Shay Levi's Profile: http://forums.techarena.in/member.php?userid=3587
View this thread: http://forums.techarena.in/showthread.php?t=85903

http://forums.techarena.i

 
Reply With Quote
 
AreWeThereYet
Guest
Posts: n/a
 
      25th November 2007
Thanks, this is proving very helpful! and gives me a better idea of how
PowerShell Scripting works.

One question I CANNOT find the answer to:

In *INX one can hit <Ctrl+D> or <Ctrl+Z> to suspend a process usually as a
prelude to sending it to the background or killing the process. How do I do
this in PowerShell?



"Shay Levi" wrote:

>
> Here's a sample Powershell script
>
> $source="C:\Backup"
> $destination="D:\temp\backup"
>
> get-childitem -path $source -recurse | where {!$_.PSIsContainer} |
> foreach {
> $path=$destination+$_.fullname.remove(0,$source.le ngth)
>
> # test if the file already exist on destination direcotry
> if(test-path $path -pathtype leaf){
>
> # if the file sizes are not equal copy the file again - overwrite
> if($_.length -ne (get-childitem $path).length){
> write-host "files $($_.name) length dont match"
> copy-item $_.fullname -destination $path
> }
> } else {
> write-host "the file $($_.name) doesn't exist, copy to destination"
> copy-item $_.fullname -destination $path -force
> }
>
> }
>
>
> --
> Shay Levi
> ------------------------------------------------------------------------
> Shay Levi's Profile: http://forums.techarena.in/member.php?userid=35878
> View this thread: http://forums.techarena.in/showthread.php?t=859035
>
> http://forums.techarena.in
>
>

 
Reply With Quote
 
Shay Levi
Guest
Posts: n/a
 
      26th November 2007

Hi

PowerShell v 2.0 (CTP) introduces the concept of a background job.
There is a workaround for v1.0:
http://jtruher.spaces.live.com/blog/...628D!130.entry


--
Shay Levi
------------------------------------------------------------------------
Shay Levi's Profile: http://forums.techarena.in/member.php?userid=35878
View this thread: http://forums.techarena.in/showthread.php?t=859035

http://forums.techarena.in

 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Powershell to set display properties? Brooke Windows XP Configuration 2 21st May 2007 05:19 PM
SLC Compare Pat Windows XP Embedded 2 8th May 2006 02:03 PM
Compare SLX files WJO14 Windows XP Embedded 5 10th February 2005 06:03 PM
Print size too large. Am killing trees Susan Windows XP Help and Support 1 25th October 2003 11:43 PM
printing folder trees Cathy Beitz Windows XP Printing / Fax 3 26th August 2003 07:21 AM


All times are GMT. The time now is 11:31 PM.
Windows XP Forums is an independent website and is not affiliated with Microsoft Corporation.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26