Copy-Item Recurse with Wildcard


  1.    27 Dec 2006 #1
    Aquinas Guest

    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

  2.    27 Dec 2006 #2
    /\\/\\o\\/\\/ [MVP] Guest

    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

  3.    27 Dec 2006 #3
    Keith Hill [MVP] Guest

    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

  4.    27 Dec 2006 #4
    Aquinas Guest

    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

  5.    28 Dec 2006 #5
    Tom G. Guest

    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

  6.    28 Dec 2006 #6
    Aquinas Guest

    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

Similar Threads
Thread Forum
Re: Remove-Item -recurse still doesn't work?
Yes, it is time to get Microsoft to clarify that issue. - Larry On 4/5/2010 11:37 PM, Clint B wrote:
PowerShell
"remove-item -recurse" bug!
I am running Windows 7 release with PS 2.0. What is the status of "remove-item -recurse" which has a horrible bug that scares the heck out of me to...
PowerShell
Copy-Item : Container cannot be copied onto existing leaf item.
I have a file rrr.config that contains the I run the script : $args = get-content -path c:\rrr.config #Make backups If ((select-string -path...
PowerShell
copy-item changing files attributes on network copy failures
I came across very strange behaviour in copy-item today. When copying a read-only file repeatedly from the network to a local folder the first copy...
PowerShell
copy-item -recurse question
I want to copy all files that match the pattern f*.sql from wherever they appear under a specified location (at any level), to a single folder. I...
PowerShell
Getting Copy-Item to display messages (like the old COPY command in CMD.EXE) ??
Folks, I really enjoy PowerShell, and its power - but sometimes, things are a bit irritating - like the fact that teh Copy-Item command doesn't...
PowerShell
Copy-Item or Copy-ItemProperty and Remote Registry.
There are a couple of questions on this one. 1) Can I use new-psdrive to mount a remote registry? 2) Can I use copy-item or Copy-ItemProperty...
PowerShell

Our Sites
  • Ten Forums
  • Eight Forums
  • Seven Forums
  • Help Me Bake
  • Site Links
  • Contact Us
  • Privacy and Cookies
  • About Us
    Windows Vista Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

    Designer Media Ltd
    All times are GMT -5. The time now is 11:25.
    .