Ironman Software Forums
Continue the conversion on the Ironman Software forums. Chat with over 1000 users about PowerShell, PowerShell Universal, and PowerShell Pro Tools.
In this post, we look at how to recursively copy a directory.
Assume we have a folder structure stored in C:\source
such as the following.
- 1
- 1
- 2
- 3
- 2
- 1
- 2
- 1
- data.txt
- data.txt
To copy the same folder structure to the C:\destination
directory, you can do the following.
Copy-Item -Path C:\source\* -Destination C:\destination\ -Recurse -Container
The resulting destination folder will contain the same directory structure as the source folder.
Directory: C:\destination
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 11/26/2021 5:32 PM 1
d---- 11/26/2021 5:32 PM 2
d---- 11/26/2021 5:32 PM 3
Directory: C:\destination\2
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 11/26/2021 5:32 PM 1
d---- 11/26/2021 5:32 PM 2
-a--- 11/26/2021 5:29 PM 7 data.txt
Directory: C:\destination\2\1
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 11/26/2021 5:29 PM 7 data.txt
Find this useful? Please consider sharing this article. Have a question about PowerShell? Contact us and we'll write a post about it.
Continue the conversion on the Ironman Software forums. Chat with over 1000 users about PowerShell, PowerShell Universal, and PowerShell Pro Tools.
Receive once-a-month updates about Ironman Software. You'll learn about our product updates and blogs related to PowerShell.