#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
Filed in: Columns, Tips and Tricks Tags: ,

One Response to "#PSTip Duplicating folder structures"

  1. Gary Smith says:

    Thanks Shay, this psh cmd is very handy!

Leave a Reply

Submit Comment

© 2017 PowerShell Magazine. All rights reserved. XHTML / CSS Valid.
Proudly designed by Theme Junkie.
%d bloggers like this: