#PSTip Duplicating folder structures

Sometimes you need to create a copy of an exiting directory structure without copying the files, and you also want to include empty folders if they exist. An example would be a deep project directory structure that needs to be created for a new project.

In the days of DOS you could use the XCOPY command. The following command creates the Windows directory structure under the temp directory of drive D:.

XCOPY c:\Windows d:\temp\Windows /E /T /I

In PowerShell you can use the Copy-Item cmdlet. The Filter scriptblock specifies the PSIsContainer property which passes on just folder objects:

Copy-Item $env:windir d:\temp\windows -Filter {PSIsContainer} -Recurse -Force
Share on: