How To Copy Folder Structure Without Files

There is no native GUI-based method to copy folder structures without copying the files with them. However, you can use the XCOPY and the Robocopy command line tools to get the job done or use a PowerShell cmdlet on a Windows PC.

Copy folder structure

We all know how to duplicate files and folders on a Windows PC – using the CTRL+ C and CTRL+ V hotkeys. However, this also copies all the content within the folder, as well as the sub-folders. This is also true for copy-pasting using the context menu.

There are times when you only wish to copy the folder/directory structure and not the files inside of them. For example, you have created a perfect file system for your 2021-2022 financial year and have sorted the files accordingly. Now you want to do the same for 2022-2023.

Instead of remaking every folder and subfolder individually, you can copy only the folder structure from one drive to another, or from one folder to another.

In this article, we are going to show you how to duplicate a folder structure without the files inside of it. Of course, any sub-directories would also be duplicated.

Copy Folder Structure Without Files in Windows

You can copy the folder structure using both Command Prompt and Windows PowerShell.

If you’d rather prefer to use the Windows Graphical User Interface (GUI), there is currently no native way of doing that in Windows. However, you can use “Duplicate Directory” by Better Editor, but it is a paid utility.

From Command Prompt

XCOPY

XCOPY is a Windows command line tool that is preinstalled in all Windows versions. There are many switches that you can use to manipulate the movement of your files and folders. However, we will only be concerning ourselves with the 2 switches discussed in this table:

SwitchDescription
/tCopies the subdirectory structure (that is, the tree) only, and not files.
/eCopies all subdirectories, even if they are empty.
XCOPY “t” and “e” switches

To copy the structure of a folder from one place to another, the following syntax is used in an elevated Command Prompt:

xcopy "[SourcePath]" "[DestinationPath]" /t /e

In this cmdlet, replace the following variables:

  • [SourcePath]: Complete path of the folder that you want to duplicate the structure of.
  • [DestinationPath]: Complete path of the directory where you want to duplicate it.

Here is an example.

Duplicate folder structure using XCOPY
Duplicate folder structure using XCOPY

As you can see in the image below, the folder structure has been duplicated from “C:\Users\subhan\Desktop\TestFolder” to “E:\WorkFolder” without the files.

Folder structure duplicated
Folder structure duplicated

You can also achieve the same with Robocopy.

Robocopy

Robocopy has an even lengthier list of switches than XCOPY, making it more functional. However, we can achieve the same with Robocopy as we did with XCOPY.

Here, we will be using the following 2 switches:

SwitchDescription
/eCopies subdirectories. This option automatically includes empty directories.
/xf *Excludes files that match the specified names or paths. Wildcard characters (* and ?) are supported.
Robocopy “e” and “xf” switches

To copy the structure of a folder from one place to another, the following syntax is used in an elevated Command Prompt:

Robocopy "[SourcePath]" "DestinationPath" /e /xf *

In this cmdlet, replace the following variables:

  • [SourcePath]: Complete path of the folder that you want to duplicate the structure of.
  • [DestinationPath]: Complete path of the directory where you want to duplicate it.

Here is an example.

Duplicate folder structure using Robocopy
Duplicate folder structure using Robocopy

At the end of the output, you also receive a statistical report of the directory movement, prompting you of the successful and the failed directory copies.

Statistics of data copy using Robocopy
Statistics of data copy using Robocopy

Similar to XCOPY, the same folder structure would have now moved from the source to the destination folder.

From PowerShell

You can also copy the structure of a folder onto another location without the files inside using Windows PowerShell.

However, this method copies the entire source folder onto the destination directory, instead of the subfolders of the source directory. To explain this better, let’s refer to the XCOPY and Robocopy methods.

The folder structure of “TestFolder” was duplicated into “WorkFolder.” However, using the PowerShell method, the entire “TestFolder” directory will be copied into the “WorkFolder” directory without the files.

To copy the structure of a folder into another location, use this command in an elevated PowerShell:

Copy-Item -LiteralPath "[SourcePath]" -Destination "[DestinationPath]" -Recurse -Filter {PSIsContainer -eq $true}

In this cmdlet, replace the following variables:

  • [SourcePath]: Complete path of the folder that you want to duplicate the structure of.
  • [DestinationPath]: Complete path of the directory where you want to duplicate it.

Here is an example.

Copy folder structure using PowerShell
Copy folder structure using PowerShell

Now as you can see in the image below, the entire “TestFolder” has been copied to “WorkFolder,” inside of which is only the directory structure duplicated, and not the files.

Entire folder is duplicated without Files using PowerShell
Entire folder is duplicated without files using PowerShell

Copy Folder Structure Without Files in MacOS

To copy the directory structure without the files on a macOS, you also need to use the Terminal. Follow these steps to duplicate the structure of a folder onto another location on a Mac:

  1. Open both the source folder and the destination folder in separate windows.

  2. Open a Terminal window.

    Tap the “Launchpad” button and type “Terminal” in the search bar, then open it.

  3. Type the following command in the Terminal window but do not run it yet:

    rsync -avf"+ */" -f"- *"
  4. Drag and drop the source folder into the window.

  5. Then drag and drop the destination folder into the Terminal window.

  6. Now press Enter.

This will now move the folder structure from the source folder to the destination location without copying the files inside.

Copy Folder Structure Without Files in Linux

To copy the structure of a folder without the files inside on a Linux platform, use these steps:

  1. Open the Terminal.

    Use the CTRL + Alt + T shortcut keys to open the Terminal.

  2. Use this cmdlet to copy the source folder structure to the destination folder:

    Replace [SourcePath] with the complete path of the source folder, and [DestinationPath] with the complete path of the destination folder.

    rsync -av -f"+ */" -f"- *" "([SourcePath])([DestinationPath])"

Your source directory structure will now be copied to the destination directory without the files.

Closing Words

Now everyone just needs to duplicate their folder structures. However, the people who need this know how helpful this feature might be, regardless of your OS platform.

Duplicating folder structures can often save minutes, if not hours, and the exact hierarchy can then be used to repeat the documentation and reporting process that you have been using in the past.

Also see:

Subhan Zafar is an established IT professional with interests in Windows and Server infrastructure testing and research, and is currently working with Itechtics as a research consultant. He has studied Electrical Engineering and is also certified by Huawei (HCNA & HCNP Routing and Switching).

Leave a Reply

Your email address will not be published. Required fields are marked *