aucuparia
aucuparia

Reputation: 2051

Copy entire folder structure in Powershell without re-creating root folder

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!

Upvotes: 3

Views: 4740

Answers (2)

brechtvhb
brechtvhb

Reputation: 1048

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

Upvotes: 0

dustinmoris
dustinmoris

Reputation: 3361

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

Works for me

Upvotes: 7

Related Questions