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!

2 Answers 2

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

Works for me

Sign up to request clarification or add additional context in comments.

3 Comments

(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.
this doesn't work with -filter option if you have subfolders
@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". stackoverflow.com/a/29082938/438664
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

1 Comment

did you mean C:\source* ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.