Discussion:
Copy-Item Recurse with Wildcard
(too old to reply)
/\\/\\o\\/\\/ [MVP]
2006-12-27 21:45:52 UTC
Permalink
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\/\/
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.
Keith Hill [MVP]
2006-12-27 22:29:16 UTC
Permalink
Post by /\\/\\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
But that doesn't preserver the directory structure of where the ps1 file was
located relative to C:\powershell.

--
Keith
Tom G.
2006-12-28 15:14:02 UTC
Permalink
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.
--
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.
Post by /\\/\\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
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\/\/
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.
Loading...