Copy-Item Recurse with Wildcard

A

Aquinas

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 Computer

O

/\\/\\o\\/\\/ [MVP]

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" <[email protected]> wrote in message
news:[email protected]
> 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 Computer

K

Keith Hill [MVP]

"/\/\o\/\/ [MVP]" <[email protected]> wrote in message
news:[email protected]
> 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 Computer

A

Aquinas

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" <[email protected]> wrote in message
> news:[email protected]
> > 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 Computer

T

Tom G.

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" <[email protected]> wrote in message
> > news:[email protected]
> > > 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 Computer

A

Aquinas

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" <[email protected]> wrote in message
> > > news:[email protected]
> > > > 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 Computer

Top