How to Copy Folder Structure without Copying the Files

Earlier, we saw how to mirror the folder contents using various tools and methods. But, there are situations where you want to copy a folder structure without copying the files in those folders. For instance, you may want to replicate the directory structure of your expenses or accounting folders in order to organize them year-wise.

I have the following folder structure to store the documents pertaining to the financial year 2018-19. For the next financial year, I would want to copy the directory structure (without copying the files) to the parent folder named 2019-20 in order to maintain uniformity.

D:\OFFICIAL\2018-19
├───Accounts
│   ├───Bank Reconciliation Statement
│   ├───Capital Gains
│   └───TDS
├───Bank Statements
│   ├───SB Accounts
│   └───Term Deposits
├───Expenses
│   ├───Computer Accessories
│   ├───Salaries and Contract fees
│   │   ├───Staff salaries
│   │   └───Upwork fees
│   ├───Travel
│   └───Web Hosting
├───Income Tax
│   ├───Advanced Tax Receipts
│   ├───IT Returns
│   ├───Refund Orders
│   ├───Self Assessment Tax Receipts
│   └───Tax filing acknowledgement
├───Letters
└───Receipts
    ├───Advertisements
    ├───Affiliate
    └───Training

The File Explorer doesn’t allow you to copy the folders without also copying the files. But, there are command-line methods and third-party tools that can easily replicate a directory structure. Let’s discuss the native command-line tools to replicate a folder structure.

Copy folder structure without copying the files

Using the XCopy command

The built-in XCopy command in Windows can copy the directory or directory tree (i.e., recursively). The switches /T /E make sure that only the folders (including empty folders) are copied without copying the files.

Open a Command Prompt window and use the following command-line syntax:

xcopy source destination /t /e

For example:

xcopy D:\Official\2018-19   D:\Official\2019-20 /t /e

If the destination folder doesn’t exist, you’ll be asked if the target/destination 2019-20 refers to a file name or directory name (F = file, D = directory) on the target. Press D to continue.

The 2018-19 folder structure is now replicated to 2019-20.

copy directory structure without files

  • /T Creates directory structure, but does not copy files. Does not include empty directories or subdirectories.
  • /T /E includes empty directories and subdirectories.

Using Robocopy

Using the built-in Robocopy, you can mirror the directory structure (without copying the files) using the following command-line syntax:

robocopy "D:\Official\2018-19" "D:\Official\2019-20" /e /xf *
  • /e – Copy subdirectories, including Empty ones.
  • /xf * – Excludes all files — denoted by the wildcard *

copy directory structure without files

Tip: If you want to exclude a particular folder(s), use the /xd switch.


Using PowerShell

Using PowerShell, you can mirror a directory tree (without copying the files) using the following command-line syntax:

Copy-Item -LiteralPath "D:\Official\2018-19" -Destination "D:\Official\2019-20" -Recurse -Filter {PSIsContainer -eq $true}

copy directory structure without files

That’s it. You’ve now replicated the directory structure under another base folder.

How to replicate the directory structure on another computer

If you want to replicate the folder structure on another computer that’s not in a network, use one of the above methods in that system to mirror a directory tree.

Then, zip the mirrored folder using File Explorer’s Share tab or via the right-click menu — Send To → Compressed (zipped) folder option.



copy directory structure without files

Copy the zip file to your computer and extract the contents to a folder. The folder structure will be maintained when you extract it into the target computer.

Alternately, use the batch file method below.


Method 4: Using PowerShell (with a Batch file)

Using PowerShell, you can get the list of folders and make a readymade batch file that has instructions to create the exact same directory structure on the target computer.

Start PowerShell and use the following command-line syntax:

(gci -Path "folder_path" -Directory -Name -Recurse) | foreach-object {"md `"" + $_ + "`""} | Out-File -FilePath "output_file" -Encoding [type]

Example:

To get the list of directories under the Backup\Accounts folder recursively and make a batch file, run the following command:

(gci -Path "D:\Backup\Accounts\" -Directory -Name -Recurse) | foreach-object {"md `"" + $_ + "`""} | Out-File -FilePath d:\output.bat -Encoding UTF8

directory list structure batch file powershell

PowerShell outputs to an ASCII file by default. It would be better if you choose UTF8 especially if you have foreign characters in the folder names. In that case, replace -encoding ASCII to -encoding UTF8 in the above command-line. Also, check out this SuperUser forum thread Files with non-ASCII characters in the file name in a Windows batch file for the workarounds (chcp command) you can use when running the batch file.

The output.txt in the above example is a batch file that creates the exact folder structure (recursively) when run on the target computer.

  1. Transfer the batch file to the target computer.
  2. Rename the file with .bat extension — e.g., output.bat
  3. Open a Command Prompt window on the target computer.
  4. Change to the base directory where you want the batch file to create the subfolders — e.g., e:\accounts.
    directory list structure batch file powershell
  5. Run the file output.bat from that directory in the Command Prompt.
  6. Optionally, verify the parent folder’s properties dialog in the source as well as the destination.
    directory list structure batch file powershell

That’s it. You’ve replicated the directory structure on the target computer using the Batch file.

Do you have any other method to replicate a directory structure on a different drive or computer? Let’s know that in the Comments section below.


One small request: If you liked this post, please share this?

One "tiny" share from you would seriously help a lot with the growth of this blog. Some great suggestions:
  • Pin it!
  • Share it to your favorite blog + Facebook, Reddit
  • Tweet it!
So thank you so much for your support, my reader. It won't take more than 10 seconds of your time. The share buttons are right below. :)

About the author

Ramesh Srinivasan founded Winhelponline.com back in 2005. He is passionate about Microsoft technologies and he has been a Microsoft Most Valuable Professional (MVP) for 10 consecutive years from 2003 to 2012.

6 thoughts on “How to Copy Folder Structure without Copying the Files”

    • I want to copy subfolders which has specific name like “High” into one folder. I have hundred’s of subfolders which many folders but I want to copy files inside “High” only. Is there any command which I can use?

  1. According to your example if I want to copy whole 2018-19 folder as it in 2019-20 folder what will be the command ?
    E.g.,
    D:\Official\2019-20\2018-19\

    Reply
  2. I use Gs Richcopy 360 to copy the structure as it without copying the files, it is a business needs, I checked every structure via myself, the program never make mistakes

    Reply

Leave a Comment