Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Strange Copy-Item behaviour

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 01-18-2007   #1 (permalink)
Romu
Guest


 

Strange Copy-Item behaviour

Dear all,
I'm trying to copy some files with different extensions while preserving the
folder structure.

I've read a couple of post on the subject but I get a weird result.

Let say the source folder is c:/src and the destination is c:/dest.

The following command :
Copy-Item -path c:/src -destination c/dest -recurse -filter "*.dll"
Works.

But if a write
Copy-Item -path c:/src -destination c/dest -recurse -filter "*.dll"
Copy-Item -path c:/src -destination c/dest -recurse -filter "*.exe"

I get :

c:/dest
- the structure with the dll (first call)
/src
- the structure with the exe (second call)

Any idea to fix this ? Or to do it differently ?

Thanks.


My System SpecsSystem Spec
Old 01-18-2007   #2 (permalink)
Romu
Guest


 

RE: Strange Copy-Item behaviour

In other world, the Copy-Item behaviour is different depending the
destination folder exists or not.

Romu

"Romu" wrote:

> Dear all,
> I'm trying to copy some files with different extensions while preserving the
> folder structure.
>
> I've read a couple of post on the subject but I get a weird result.
>
> Let say the source folder is c:/src and the destination is c:/dest.
>
> The following command :
> Copy-Item -path c:/src -destination c/dest -recurse -filter "*.dll"
> Works.
>
> But if a write
> Copy-Item -path c:/src -destination c/dest -recurse -filter "*.dll"
> Copy-Item -path c:/src -destination c/dest -recurse -filter "*.exe"
>
> I get :
>
> c:/dest
> - the structure with the dll (first call)
> /src
> - the structure with the exe (second call)
>
> Any idea to fix this ? Or to do it differently ?
>
> Thanks.
>

My System SpecsSystem Spec
Old 01-18-2007   #3 (permalink)
Romu
Guest


 

RE: Strange Copy-Item behaviour

In other world, the Copy-Item behaviour is different depending the
destination folder exists or not.

Romu

"Romu" wrote:

> Dear all,
> I'm trying to copy some files with different extensions while preserving the
> folder structure.
>
> I've read a couple of post on the subject but I get a weird result.
>
> Let say the source folder is c:/src and the destination is c:/dest.
>
> The following command :
> Copy-Item -path c:/src -destination c/dest -recurse -filter "*.dll"
> Works.
>
> But if a write
> Copy-Item -path c:/src -destination c/dest -recurse -filter "*.dll"
> Copy-Item -path c:/src -destination c/dest -recurse -filter "*.exe"
>
> I get :
>
> c:/dest
> - the structure with the dll (first call)
> /src
> - the structure with the exe (second call)
>
> Any idea to fix this ? Or to do it differently ?
>
> Thanks.
>

My System SpecsSystem Spec
Old 01-18-2007   #4 (permalink)
Andrew Watt [MVP]
Guest


 

Re: Strange Copy-Item behaviour

Hi,

Yes, I would expect (on the basis of move-item) that behaviour is
different depending on whether or not the destination folder exists or
not.

Take a look at the move-item thread beginning on 15th January for
illustrations of possible approaches.

Andrew Watt MVP

On Thu, 18 Jan 2007 06:06:02 -0800, Romu
<Romu@discussions.microsoft.com> wrote:

>In other world, the Copy-Item behaviour is different depending the
>destination folder exists or not.
>
>Romu
>
>"Romu" wrote:
>
>> Dear all,
>> I'm trying to copy some files with different extensions while preserving the
>> folder structure.
>>
>> I've read a couple of post on the subject but I get a weird result.
>>
>> Let say the source folder is c:/src and the destination is c:/dest.
>>
>> The following command :
>> Copy-Item -path c:/src -destination c/dest -recurse -filter "*.dll"
>> Works.
>>
>> But if a write
>> Copy-Item -path c:/src -destination c/dest -recurse -filter "*.dll"
>> Copy-Item -path c:/src -destination c/dest -recurse -filter "*.exe"
>>
>> I get :
>>
>> c:/dest
>> - the structure with the dll (first call)
>> /src
>> - the structure with the exe (second call)
>>
>> Any idea to fix this ? Or to do it differently ?
>>
>> Thanks.
>>

My System SpecsSystem Spec
Old 01-19-2007   #5 (permalink)
Romu
Guest


 

Re: Strange Copy-Item behaviour

Thanks Andrew but doesn't this seem too much tricky just to do a copy ??

I tried another simple thing :
Copy-Item -path $path.stable -destination $path.msbse -recurse -exclude
"*.pdb *.so *.log *.txt"

And this doesn't work, all files are copied even the pdb, log...

For me it's completely crazy PS doens't provide a simple an efficient way to
just copy files !!

Anyway, thanks for your help Andrew.

Romu

"Andrew Watt [MVP]" wrote:

> Hi,
>
> Yes, I would expect (on the basis of move-item) that behaviour is
> different depending on whether or not the destination folder exists or
> not.
>
> Take a look at the move-item thread beginning on 15th January for
> illustrations of possible approaches.
>
> Andrew Watt MVP
>
> On Thu, 18 Jan 2007 06:06:02 -0800, Romu
> <Romu@discussions.microsoft.com> wrote:
>
> >In other world, the Copy-Item behaviour is different depending the
> >destination folder exists or not.
> >
> >Romu
> >
> >"Romu" wrote:
> >
> >> Dear all,
> >> I'm trying to copy some files with different extensions while preserving the
> >> folder structure.
> >>
> >> I've read a couple of post on the subject but I get a weird result.
> >>
> >> Let say the source folder is c:/src and the destination is c:/dest.
> >>
> >> The following command :
> >> Copy-Item -path c:/src -destination c/dest -recurse -filter "*.dll"
> >> Works.
> >>
> >> But if a write
> >> Copy-Item -path c:/src -destination c/dest -recurse -filter "*.dll"
> >> Copy-Item -path c:/src -destination c/dest -recurse -filter "*.exe"
> >>
> >> I get :
> >>
> >> c:/dest
> >> - the structure with the dll (first call)
> >> /src
> >> - the structure with the exe (second call)
> >>
> >> Any idea to fix this ? Or to do it differently ?
> >>
> >> Thanks.
> >>

>

My System SpecsSystem Spec
Old 01-20-2007   #6 (permalink)
mikes.net
Guest


 

Re: Strange Copy-Item behaviour

On Jan 19, 3:15 pm, Romu <R...@discussions.microsoft.com> wrote:
> Thanks Andrew but doesn't this seem too much tricky just to do a copy ??
>
> I tried another simple thing :
> Copy-Item -path $path.stable -destination $path.msbse -recurse -exclude
> "*.pdb *.so *.log *.txt"
>
> And this doesn't work, all files are copied even the pdb, log...
>
> For me it's completely crazy PS doens't provide a simple an efficient way to
> just copy files !!
>
> Anyway, thanks for your help Andrew.


Agreed, and I hope the Powershell team is listening to you. When it
comes to file handling, you are probably better off avoiding one liners
and just writing a little script, in which case, Powershell excels. It
is a shame that such an otherwise exemplary and revolutionary language
falls down at exactly the wrong place, one liner file handling. As
another example, try writing a recursive search and replace one liner,
or do paragraph based search instead of line based. Powershell can do
these things easily as a script, but on the command line it can't begin
to compare with the ease of Perl/Ruby.

I also have two minor requests, to improve the one liner experience:
Change the Cmdlet naming convention to make them less verbose, and
would it be possible to type just a % or ? instead of %{ and ?{ at
least in simple cases?

And BTW, aliases and scripts are not cure alls. They should not be
used as permanent band aids to avoid fixing design flaws or
limitations. They do make it harder to share, and harder to move
around. And nobody likes having 2 names for 1 thing.

Now, as a scripting language, Powershell blows the doors out. Moreso
than people yet realize.

IMHO.

Thanks,
Mike

My System SpecsSystem Spec
Old 01-20-2007   #7 (permalink)
Keith Hill [MVP]
Guest


 

Re: Strange Copy-Item behaviour

"mikes.net" <michael.net@gmail.com> wrote in message
news:1169310403.576091.234900@v45g2000cwv.googlegroups.com...
> Agreed, and I hope the Powershell team is listening to you. When it
> comes to file handling, you are probably better off avoiding one liners
> and just writing a little script, in which case, Powershell excels. It
> is a shame that such an otherwise exemplary and revolutionary language
> falls down at exactly the wrong place, one liner file handling. As
> another example, try writing a recursive search and replace one liner,
> or do paragraph based search instead of line based. Powershell can do
> these things easily as a script, but on the command line it can't begin
> to compare with the ease of Perl/Ruby.


I agree that the behavior of filtering on copy-item isn't great. I was
never a Perl user so I'm curious about what these Perl one-liners look like
i.e. those that aren't so easy to do as a one liner in PoSh.

> And BTW, aliases and scripts are not cure alls. They should not be
> used as permanent band aids to avoid fixing design flaws or
> limitations. They do make it harder to share, and harder to move
> around. And nobody likes having 2 names for 1 thing.


I really like having one very terse name (alias) for interactive typing at
the console. However those terse names aren't great for script readability
so I like that the actual cmdlet names are fairly self describing even if
they are a bit long.

> Now, as a scripting language, Powershell blows the doors out. Moreso
> than people yet realize.


Yeah it's a really nice scripting language.

--
Keith


My System SpecsSystem Spec
Old 01-20-2007   #8 (permalink)
mikes.net
Guest


 

Re: Strange Copy-Item behaviour

Been so long I had to look one up. Here's a recursive search and
replace on Unix:

perl -p -i -e 's/oldstring/newstring/g' `find ./ -name *.html`

I believe the -p is causing automatic looping over the input file, the
-i probably means "in place", I think I recall that -i.bak would cause
it to automatically create backups (very important!), or something like
that. Just google "Perl One Liners " and you'll find lots of amazingly
powerful yet terse and simple commands.

Both Perl/Ruby also have switches that change the input and output
separators. For example perl -00 causes automatic paragraph parsing, a
*very* handy thing. Powershell oddly only has $OFS. It needs a $IFS
as well.

And BTW, I don't agree that verbosity is good on the command line.
Somehow Unix had a wonderful scripting environment for many years that
was very terse.

Mike

On Jan 20, 3:08 pm, "Keith Hill [MVP]"
<r_keith_h...@mailhot.moc.nospam> wrote:
> "mikes.net" <michael....@gmail.com> wrote in messagenews:1169310403.576091.234900@v45g2000cwv.googlegroups.com...
>
> > Agreed, and I hope the Powershell team is listening to you. When it
> > comes to file handling, you are probably better off avoiding one liners
> > and just writing a little script, in which case, Powershell excels. It
> > is a shame that such an otherwise exemplary and revolutionary language
> > falls down at exactly the wrong place, one liner file handling. As
> > another example, try writing a recursive search and replace one liner,
> > or do paragraph based search instead of line based. Powershell can do
> > these things easily as a script, but on the command line it can't begin
> > to compare with the ease of Perl/Ruby.I agree that the behavior of filtering on copy-item isn't great. I was

> never a Perl user so I'm curious about what these Perl one-liners look like
> i.e. those that aren't so easy to do as a one liner in PoSh.
>
> > And BTW, aliases and scripts are not cure alls. They should not be
> > used as permanent band aids to avoid fixing design flaws or
> > limitations. They do make it harder to share, and harder to move
> > around. And nobody likes having 2 names for 1 thing.I really like having one very terse name (alias) for interactive typing at

> the console. However those terse names aren't great for script readability
> so I like that the actual cmdlet names are fairly self describing even if
> they are a bit long.
>
> > Now, as a scripting language, Powershell blows the doors out. Moreso
> > than people yet realize.Yeah it's a really nice scripting language.

>
> --
> Keith


My System SpecsSystem Spec
Old 01-20-2007   #9 (permalink)
mikes.net
Guest


 

Re: Strange Copy-Item behaviour

Ah, I found some of my old Ruby/Windows notes. These are nicely terse.


Non recursive paragraph grep:

ruby -00 -ne 'print if /your expression here/'

Substitute all occurences of PATTERN with STRING in argument files:

ruby -i -pe "gsub!(/PATTERN/, STRING)" file1 file2 ...

Print section of file between two regular expressions, /foo/ and /bar/
$ type <file> | ruby -ne '@found=true if $_ =~ /foo/; next unless
@found; puts $_; exit if $_ =~ /bar/'

Before powershell, recursing on Windows was horrible... Find all
asp.net files containing "todo":

for /F "usebackq" %f in (`dir /s /b /oe *.aspx *.ascx *.cs`) do
@ruby -wne "print $FILENAME, ' ', $_ if /todo/i" %f

Mike

My System SpecsSystem Spec
Old 01-20-2007   #10 (permalink)
Keith Hill [MVP]
Guest


 

Re: Strange Copy-Item behaviour

"mikes.net" <michael.net@gmail.com> wrote in message
news:1169330262.827116.40690@51g2000cwl.googlegroups.com...
> Been so long I had to look one up. Here's a recursive search and
> replace on Unix:
>
> perl -p -i -e 's/oldstring/newstring/g' `find ./ -name *.html`


Having it modify the files in place (with a backup) is definitely handy.

> And BTW, I don't agree that verbosity is good on the command line.


I don't like the verbosity the command prompt either. I use aliases heavily
at the prompt. Where I do like the verbosity is in scripts.

> Somehow Unix had a wonderful scripting environment for many years that
> was very terse.

My primary shell scripting environment before PoSH was KornShell. I've
never found KSH scripts particularly easy to read. In fact they can be
pretty cryptic.

--
Keith


My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Help - Doing XCopy in Copy-Item strange result Kiron PowerShell 1 04-22-2008 07:51 PM
strange behaviour in excel after SP1 Delboy Vista General 2 03-20-2008 10:38 AM
copy-item changing files attributes on network copy failures jas PowerShell 4 01-31-2008 12:39 PM
Behaviour of copy-item when parameters are supplied initially or not Andrew Watt [MVP] PowerShell 0 01-11-2007 03:03 PM
Conflicting behaviour of rename-item cmdlet Samuel Denbigh Leslie PowerShell 4 01-10-2007 08:00 AM


Update your Vista Drivers Update Your Drivers Now!!

Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008