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.
Table of Contents
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:
Switch | Description |
/t | Copies the subdirectory structure (that is, the tree) only, and not files. |
/e | Copies all subdirectories, even if they are empty. |
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.
![How To Copy Folder Structure Without Files 1 Duplicate folder structure using XCOPY](https://www.itechtics.com/wp-content/uploads/2022/12/Duplicate-folder-structure-using-XCOPY-700x386.jpg)
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.
![How To Copy Folder Structure Without Files 2 Folder structure duplicated](https://www.itechtics.com/wp-content/uploads/2022/12/Folder-structure-duplicated-700x394.jpg)
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:
Switch | Description |
/e | Copies subdirectories. This option automatically includes empty directories. |
/xf * | Excludes files that match the specified names or paths. Wildcard characters (* and ?) are supported. |
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.
![How To Copy Folder Structure Without Files 3 Duplicate folder structure using Robocopy](https://www.itechtics.com/wp-content/uploads/2022/12/Duplicate-folder-structure-using-Robocopy-700x394.jpg)
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.
![How To Copy Folder Structure Without Files 4 Statistics of data copy using Robocopy](https://www.itechtics.com/wp-content/uploads/2022/12/Statistics-of-data-copy-using-Robocopy-700x394.jpg)
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.
![How To Copy Folder Structure Without Files 5 Copy folder structure using PowerShell](https://www.itechtics.com/wp-content/uploads/2022/12/Copy-folder-structure-using-PowerShell-700x394.jpg)
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.
![How To Copy Folder Structure Without Files 6 Entire folder is duplicated without Files using PowerShell](https://www.itechtics.com/wp-content/uploads/2022/12/Entire-folder-is-duplicated-without-Files-using-PowerShell-700x394.jpg)
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:
-
Open both the source folder and the destination folder in separate windows.
-
Open a Terminal window.
Tap the “Launchpad” button and type “Terminal” in the search bar, then open it.
-
Type the following command in the Terminal window but do not run it yet:
rsync -avf"+ */" -f"- *"
-
Drag and drop the source folder into the window.
-
Then drag and drop the destination folder into the Terminal window.
-
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:
-
Open the Terminal.
Use the CTRL + Alt + T shortcut keys to open the Terminal.
-
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.
2 comments
Samit Gandhi
When you copy the source folder to a window is that supposed to be the Terminal Window just like the destination folder?7
Subhan Zafar
Hello Samit,
We appreciate your query.
By the looks of it, I believe that you are referring to the steps to copy a folder structure in macOS; specifically Step #4. If yes, then here is some clarification:
Yes, you need to drag and drop the source folder into the Terminal window. Once done, drag and drop the destination folder into the Terminal window.
This will automatically insert the source’s and the destination’s path into the command, after which you can press “Enter” to run it.
Since macOS is a Linux-based OS, it uses a similar syntax when running commands. If you can compare the commands for Linux and macOS above, you will notice that they are similar, except for the source folder path and the destination folder path. These are given by dragging and dropping the folders (in the case of macOS).