Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 help and support Forum Windows 8 Forum Vista Tutorials

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.

Go Back   Vista Forums > Vista Newsgroup Archive > Misc Newsgroups > PowerShell

Vista - Copy-Item Recurse with Wildcard


 
 
12-27-2006   #1 (permalink)
Aquinas


 

Copy-Item Recurse with Wildcard

Can you use Copy-Item recursively with a wildcard? Something like:

Copy-Item c:\folder\*.txt c:\folder2 -Recurse



That's just one of many variations of this. None worked. Using the wildcard
is important. I _can_ get a recursive copy to work without wildcards. It
should also preserve the folder structure.

My System SpecsSystem Spec
12-27-2006   #2 (permalink)
/\\/\\o\\/\\/ [MVP]


 

Re: Copy-Item Recurse with Wildcard

works for me (and i'm used to working like this now in PoSH ),

dir -recurse c:\powershell *.ps1 | copy -destination c:\test -whatif

still should work IMHO (at least second example (using provider function)
but do only one level :

copy c:\powershell\* c:\test -include *.ps1 -rec -whatif
copy c:\powershell\* c:\test -filter *.ps1 -rec -whatif

guess directories are excluded also then (makes some sence in object terms
(directory being just another object, but the filter is provide specific )
still as -filter is provider specific should be able to this while in the
filesystem provider i would think.

thoughts ?

greetings /\/\o\/\/

"Aquinas" <Aquinas@discussions.microsoft.com> wrote in message
news:E9104512-96B0-4526-9AEB-88E8A68C6C51@microsoft.com...
> Can you use Copy-Item recursively with a wildcard? Something like:
>
> Copy-Item c:\folder\*.txt c:\folder2 -Recurse
>
> That's just one of many variations of this. None worked. Using the
> wildcard
> is important. I _can_ get a recursive copy to work without wildcards. It
> should also preserve the folder structure.
>


My System SpecsSystem Spec
12-27-2006   #3 (permalink)
Keith Hill [MVP]


 

Re: Copy-Item Recurse with Wildcard

"/\/\o\/\/ [MVP]" <mow001@hotmail.NoSpam> wrote in message
news:A74D5449-2CC7-4CFE-AF27-466C72ED602B@microsoft.com...
> works for me (and i'm used to working like this now in PoSH ),
>
> dir -recurse c:\powershell *.ps1 | copy -destination c:\test -whatif


But that doesn't preserver the directory structure of where the ps1 file was
located relative to C:\powershell.

--
Keith


My System SpecsSystem Spec
12-27-2006   #4 (permalink)
Aquinas


 

Re: Copy-Item Recurse with Wildcard

I'd like to know if it can be done with only the Copy-Item command, and I'd
like it to preserve the directory structure. To reiterate, I'm looking to use
Copy-Item recursively with a wildcard while preserving the directory
structure.

The Powershell help doesn't say you can't but doesn't say you can either.
Although I think it's implied that it can, or at least I get the impression
that it should be doable. After all, it lists -Recurse and -Container as
parameter options.

It seems odd that I had to end up going to cmd.exe to do a Copy /s to get it
done.

"/\/\o\/\/ [MVP]" wrote:

> works for me (and i'm used to working like this now in PoSH ),
>
> dir -recurse c:\powershell *.ps1 | copy -destination c:\test -whatif
>
> still should work IMHO (at least second example (using provider function)
> but do only one level :
>
> copy c:\powershell\* c:\test -include *.ps1 -rec -whatif
> copy c:\powershell\* c:\test -filter *.ps1 -rec -whatif
>
> guess directories are excluded also then (makes some sence in object terms
> (directory being just another object, but the filter is provide specific )
> still as -filter is provider specific should be able to this while in the
> filesystem provider i would think.
>
> thoughts ?
>
> greetings /\/\o\/\/
>
> "Aquinas" <Aquinas@discussions.microsoft.com> wrote in message
> news:E9104512-96B0-4526-9AEB-88E8A68C6C51@microsoft.com...
> > Can you use Copy-Item recursively with a wildcard? Something like:
> >
> > Copy-Item c:\folder\*.txt c:\folder2 -Recurse
> >
> > That's just one of many variations of this. None worked. Using the
> > wildcard
> > is important. I _can_ get a recursive copy to work without wildcards. It
> > should also preserve the folder structure.
> >

>

My System SpecsSystem Spec
12-28-2006   #5 (permalink)
Tom G.


 

Re: Copy-Item Recurse with Wildcard

Maybe the following will do what you're trying to achieve. On my
machine, this copied all text files in all subdirectories of C:\source
and copied them to C:\Dest while preserving the folder structure.

copy-item -rec -filter *.txt C:\Source C:\Dest

Tom G.
--



Aquinas wrote:

> I'd like to know if it can be done with only the Copy-Item command,
> and I'd like it to preserve the directory structure. To reiterate,
> I'm looking to use Copy-Item recursively with a wildcard while
> preserving the directory structure.
>
> The Powershell help doesn't say you can't but doesn't say you can
> either. Although I think it's implied that it can, or at least I get
> the impression that it should be doable. After all, it lists -Recurse
> and -Container as parameter options.
>
> It seems odd that I had to end up going to cmd.exe to do a Copy /s to
> get it done.
>
> "/\/\o\/\/ [MVP]" wrote:
>
> > works for me (and i'm used to working like this now in PoSH ),
> >
> > dir -recurse c:\powershell *.ps1 | copy -destination c:\test -whatif
> >
> > still should work IMHO (at least second example (using provider
> > function) but do only one level :
> >
> > copy c:\powershell\* c:\test -include *.ps1 -rec -whatif
> > copy c:\powershell\* c:\test -filter *.ps1 -rec -whatif
> >
> > guess directories are excluded also then (makes some sence in
> > object terms (directory being just another object, but the filter
> > is provide specific ) still as -filter is provider specific should
> > be able to this while in the filesystem provider i would think.
> >
> > thoughts ?
> >
> > greetings /\/\o\/\/
> >
> > "Aquinas" <Aquinas@discussions.microsoft.com> wrote in message
> > news:E9104512-96B0-4526-9AEB-88E8A68C6C51@microsoft.com...
> > > Can you use Copy-Item recursively with a wildcard? Something like:
> > >
> > > Copy-Item c:\folder\*.txt c:\folder2 -Recurse
> > >
> > > That's just one of many variations of this. None worked. Using
> > > the wildcard
> > > is important. I can get a recursive copy to work without
> > > wildcards. It should also preserve the folder structure.
> > >

> >

My System SpecsSystem Spec
12-28-2006   #6 (permalink)
Aquinas


 

Re: Copy-Item Recurse with Wildcard

Yes, that did it! It's the filter option. I guess I was fixated on the
-include option, after all, that's what I use when I use get-childitem
recursively.

thanks.

"Tom G." wrote:

> Maybe the following will do what you're trying to achieve. On my
> machine, this copied all text files in all subdirectories of C:\source
> and copied them to C:\Dest while preserving the folder structure.
>
> copy-item -rec -filter *.txt C:\Source C:\Dest
>
> Tom G.
> --
>
>
>
> Aquinas wrote:
>
> > I'd like to know if it can be done with only the Copy-Item command,
> > and I'd like it to preserve the directory structure. To reiterate,
> > I'm looking to use Copy-Item recursively with a wildcard while
> > preserving the directory structure.
> >
> > The Powershell help doesn't say you can't but doesn't say you can
> > either. Although I think it's implied that it can, or at least I get
> > the impression that it should be doable. After all, it lists -Recurse
> > and -Container as parameter options.
> >
> > It seems odd that I had to end up going to cmd.exe to do a Copy /s to
> > get it done.
> >
> > "/\/\o\/\/ [MVP]" wrote:
> >
> > > works for me (and i'm used to working like this now in PoSH ),
> > >
> > > dir -recurse c:\powershell *.ps1 | copy -destination c:\test -whatif
> > >
> > > still should work IMHO (at least second example (using provider
> > > function) but do only one level :
> > >
> > > copy c:\powershell\* c:\test -include *.ps1 -rec -whatif
> > > copy c:\powershell\* c:\test -filter *.ps1 -rec -whatif
> > >
> > > guess directories are excluded also then (makes some sence in
> > > object terms (directory being just another object, but the filter
> > > is provide specific ) still as -filter is provider specific should
> > > be able to this while in the filesystem provider i would think.
> > >
> > > thoughts ?
> > >
> > > greetings /\/\o\/\/
> > >
> > > "Aquinas" <Aquinas@discussions.microsoft.com> wrote in message
> > > news:E9104512-96B0-4526-9AEB-88E8A68C6C51@microsoft.com...
> > > > Can you use Copy-Item recursively with a wildcard? Something like:
> > > >
> > > > Copy-Item c:\folder\*.txt c:\folder2 -Recurse
> > > >
> > > > That's just one of many variations of this. None worked. Using
> > > > the wildcard
> > > > is important. I can get a recursive copy to work without
> > > > wildcards. It should also preserve the folder structure.
> > > >
> > >

>

My System SpecsSystem Spec
 

Copy-Item Recurse with Wildcard problems?



Thread Tools


Similar topics to: Copy-Item Recurse with Wildcard
Thread Forum
Re: Remove-Item -recurse still doesn't work? PowerShell
"remove-item -recurse" bug! PowerShell
Copy-Item : Container cannot be copied onto existing leaf item. PowerShell
copy-item changing files attributes on network copy failures PowerShell
copy-item -recurse question PowerShell


Vista Forums 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 Ltd

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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50