Copy Folder Structure without Copying Files in Windows

There are situations where you want to copy a folder structure without copying the files in that folder and sub-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 directory 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 files) to the parent folder named 2019-20 to maintain uniformity.

D:\OFFICIAL\2018-19
├───Accounts
│   ├───Bank Reconciliation Statement
│   ├───Capital Gains
│   └───TDS
├───Bank Statements
│   ├───SB Accounts
│   └───Term Deposits
├───Income Tax
│   ├───Advanced Tax Receipts
│   ├───IT Returns
│   ├───Refund Orders
│   ├───Self Assessment Tax Receipts
│   └───Tax filing acknowledgement

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.

Important: If your folder names contain spaces, then make sure to enclose the folder path within double-quotes when running one of the commands listed in this article.

Copy folder structure without copying files

Using the XCOPY command

The built-in XCOPY command in Windows can copy the directory or directory tree (i.e., recursively).

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

xcopy source destination /t /e

The switches /T /E make sure that only the folders (including empty folders) are copied without copying the files.

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.

Note: If your folder names contain spaces, then make sure to enclose the folder path within double quotes when running the command.

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 files) using the following command-line:

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.



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 (output a batch file)

Using PowerShell, you can get the list of folders and make a readymade batch file that can create the same directory structure when it’s run from 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 to 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.

  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 copied the folder structure on the target computer using batch file.


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. It won't take more than 10 seconds of your time. The share buttons are right below. :)

Ramesh Srinivasan is passionate about Microsoft technologies and he has been a consecutive ten-time recipient of the Microsoft Most Valuable Professional award in the Windows Shell/Desktop Experience category, from 2003 to 2012. He loves to troubleshoot and write about Windows. Ramesh founded Winhelponline.com in 2005.

11 thoughts on “Copy Folder Structure without Copying Files in Windows”

    • 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
  3. x copy is great! One note if your directories (folders) have spaces then you’ll want to enclose each in quotation marks. Otherwise it will think that at each space there is a new directory.

    Reply
  4. Is there a way to have Windows or some other app automatically build the folder tree that is shown at the beginning of this article with parent and sub folders shown with lines leading to parent and subfolders? The only options I have seen are for txt lists and those are not what I am looking for…

    Reply
    • @Terry: Try the TREE command.

      tree /?
      Graphically displays the folder structure of a drive or path.
      
      TREE [drive:][path] [/F] [/A]
      
         /F   Display the names of the files in each folder.
         /A   Use ASCII instead of extended characters.

Leave a Reply to Eric Cancel reply