3

I have some folders called

C:\Source
C:\Destination

C:\Source contains 
  ---> FolderA (having few files)
  ---> FolderB (having few files)
  ... etc

I want to copy all subdirectories into C:\Destination

How would I write Powershell program which takes all multiple variable subfolders and copies into Directory?

This does not work, as it is results in copying all of Source Folder into Destination resulting in

How to copy folder with subfolders?

C:\Destination\Source

Would like to keep same subdirectory folder structure

  • 1
    usually, the best thing to use for this is robocopy. [*grin*] you _can_ call it from inside powershell ... – Lee_Dailey May 26 '19 at 00:55

1 Answers1

4

This seems to work

Get-ChildItem -Path "C:\Source" |
Copy-Item -Force -Destination "C:\Destination" -Recurse -Container