3

I have a source folder like this:

source_folder -|
               |-> sub_folder1
               |-> sub_folder2
               |-> sub_folder3

where sub_folder1, sub_folder2 and sub_folder3 have themselves got sub-folders and files. I also have an existing empty folder dest_folder and I want to end up with:

dest_folder -|
             |-> sub_folder1
             |-> sub_folder2
             |-> sub_folder3

where the sub-folders are copies of the first lot. I tried Copy-Item source_folder dest_folder -Recurse but that left me with:

dest_folder -|
             |-> source_folder -|
                                |-> sub_folder1
                                |-> sub_folder2
                                |-> sub_folder3

It seems like this should be possible with a simple Copy-Item if only I could find the right combination of wildcards and switches!

aucuparia
  • 2,021
  • 20
  • 27

2 Answers2

7
Copy-Item C:\source\* C:\dest -Recurse

Works for me

dustinmoris
  • 3,195
  • 3
  • 25
  • 33
  • (changed my mind - this might help someone as the docs are not clear on this point). I thought I'd tried this but obviously mistyped/did something stupid! Anyhow this works fine. – aucuparia Mar 11 '15 at 12:30
  • 2
    this doesn't work with -filter option if you have subfolders – AndreiM Sep 25 '18 at 09:23
  • @AndreiM Remove the `\*` from the source path, and delete the destination first. `rm -r -ErrorAction:SilentlyContinue C:\dest; Copy-Item C:\source C:\dest -Recurse -Filter "*.txt"`. https://stackoverflow.com/a/29082938/438664 – MakotoE Jun 16 '19 at 06:45
0

I had the same issue because i used this command without the * you get the result as you had.

Copy-Item C:\source C:\dest -Recurse
brechtvhb
  • 1,029
  • 2
  • 13
  • 26