none
Copy many files from sub-folders (of varying depth)? RRS feed

  • Question

  • Hi All,

    I have an email archive consisting of hundreds of sub-folders; each of which contains a single email (EML) file. My goal is to copy all of the individual email files into a single 'master' folder. I am stuck on how to script a copy command that will take individual files from so many sub-folders, of (sometimes) varying depth, and put them all into one master folder.

    As noted my sub-folders can have varying depth;

    C:\folder a\folder b\folder c\cat.eml
    C:\folder a\folder b\folder c\folder d\dog.eml
    C:\folder a\folder b\folder c\folder d\folder e\fish.eml

    For example I essentially need to copy the cat.eml, dog.eml, and fish.eml files to a single folder.

    If anybody can offer any advice on how to achieve this copy operation it will be greatly appreciated.

    Kind Regards,

    Davo

    • Moved by Bill_Stewart Wednesday, December 12, 2018 5:20 PM This is not "scripts on demand"
    Thursday, August 2, 2018 1:38 AM

All replies

  • Get-Childitem -Path c:\rootfolder\* -File -Recurse | Copy-Item c:\targetfolder

    Why is that so hard?


    \_(ツ)_/

    Thursday, August 2, 2018 2:13 AM
  • Thanks. Your a legend!

    Sorry.  I am not dead yet.  I'll let you know when that happens so you can declare me a legend.


    \_(ツ)_/

    Thursday, August 2, 2018 3:39 AM
  • I got this error 'Copy-Item : The input object cannot be bound to any parameters for the command either because the command does not
    take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.', and have no idea what it means?
    Thursday, August 2, 2018 4:07 AM
  • The code I posted cannot return that error.  What did you do to make that happen?

    Without the compete error message we cannot help.


    \_(ツ)_/

    Thursday, August 2, 2018 4:15 AM
  • Get-Childitem -Path c:\rootfolder\* -File -Recurse | Copy-Item c:\targetfolder

    Why is that so hard?


    \_(ツ)_/

    I got this error 'Copy-Item : The input object cannot be bound to any parameters for the command either because the command does not
    take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.', and have no idea what it means?

    You are missing the -Destination parameter in the Copy-Item cmdlet.

    Get-ChildItem -Path c:\rootfolder\* -Recurse -File | Copy-Item -Destination c:\targetfolder
    

    Thursday, August 2, 2018 5:07 AM
  • Hi Darts75,

    Have you been able to find a solution? If your question has been answered in this thread, please don't forget to mark the thread as answered. It helps improve the chance of others with similar questions obtaining answers.

    Friday, August 17, 2018 12:16 PM