{"id":10509,"date":"2019-07-28T14:56:23","date_gmt":"2019-07-28T09:26:23","guid":{"rendered":"http:\/\/198.58.113.91\/blog\/?p=10509"},"modified":"2022-05-16T16:39:11","modified_gmt":"2022-05-16T11:09:11","slug":"how-to-copy-folder-structure-without-copying-files","status":"publish","type":"post","link":"https:\/\/www.winhelponline.com\/blog\/how-to-copy-folder-structure-without-copying-files\/","title":{"rendered":"Copy Folder Structure without Copying Files in Windows"},"content":{"rendered":"<p>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.<\/p>\n<p>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.<!--more--><\/p>\n<pre>D:\\OFFICIAL\\2018-19\r\n\u251c\u2500\u2500\u2500Accounts\r\n\u2502   \u251c\u2500\u2500\u2500Bank Reconciliation Statement\r\n\u2502   \u251c\u2500\u2500\u2500Capital Gains\r\n\u2502   \u2514\u2500\u2500\u2500TDS\r\n\u251c\u2500\u2500\u2500Bank Statements\r\n\u2502   \u251c\u2500\u2500\u2500SB Accounts\r\n\u2502   \u2514\u2500\u2500\u2500Term Deposits\r\n\u251c\u2500\u2500\u2500Income Tax\r\n\u2502   \u251c\u2500\u2500\u2500Advanced Tax Receipts\r\n\u2502   \u251c\u2500\u2500\u2500IT Returns\r\n\u2502   \u251c\u2500\u2500\u2500Refund Orders\r\n\u2502   \u251c\u2500\u2500\u2500Self Assessment Tax Receipts\r\n\u2502   \u2514\u2500\u2500\u2500Tax filing acknowledgement<\/pre>\n<p>The File Explorer doesn&#8217;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&#8217;s discuss the native command-line tools to replicate a folder structure.<\/p>\n<div id=\"toc\">\n<p><strong>Copy folder structure<\/strong><\/p>\n<ul>\n<li><a href=\"#xcopy\">Method 1: Using XCOPY<\/a><\/li>\n<li><a href=\"#robocopy\">Method 2: Using RoboCopy<\/a><\/li>\n<li><a href=\"#powershell\">Method 3: Using PowerShell<\/a><\/li>\n<li><a href=\"#powershell_batch_file\">Method 4: Using PowerShell (output a batch file)<\/a><\/li>\n<\/ul>\n<\/div>\n<p><em><strong>Important:<\/strong> 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.<\/em><\/p>\n<h2>Copy folder structure without copying files<\/h2>\n<h3><a id=\"xcopy\"><\/a>Using the XCOPY command<\/h3>\n<p>The built-in XCOPY command in Windows can copy the directory or directory tree (i.e., recursively).<\/p>\n<p>Open a Command Prompt window and use the following command-line syntax:<\/p>\n<pre>xcopy source destination \/t \/e<\/pre>\n<p>The switches <code>\/T \/E<\/code> make sure that only the folders (including empty folders) are copied without copying the files.<\/p>\n<p>For example:<\/p>\n<pre>xcopy \"D:\\Official\\2018-19\"   \"D:\\Official\\2019-20\" \/t \/e<\/pre>\n<p>If the destination folder doesn&#8217;t exist, you&#8217;ll be asked if the target\/destination <code>2019-20<\/code> refers to a file name or directory name (<code>F<\/code> = file, <code>D<\/code> = directory) on the target.\u00a0Press <code>D<\/code> to continue.<\/p>\n<p>The <code>2018-19<\/code> folder structure is now replicated to <code>2019-20<\/code>.<\/p>\n<p><em><strong>Note:<\/strong> If your folder names contain spaces, then make sure to enclose the folder path within double quotes when running the command.<\/em><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10510\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/07\/copy-folder-structure-1.png\" alt=\"copy directory structure without files\" width=\"699\" height=\"560\" \/><\/p>\n<ul>\n<li><code> \/T<\/code> Creates directory structure, but does not copy files. Does not include empty directories or subdirectories.<\/li>\n<li><code>\/T \/E<\/code> includes empty directories and subdirectories.<\/li>\n<\/ul>\n<hr \/>\n<h3><a id=\"robocopy\"><\/a>Using Robocopy<\/h3>\n<p>Using the built-in Robocopy, you can mirror the directory structure (without copying the files) using the following command-line syntax:<\/p>\n<pre>robocopy \"D:\\Official\\2018-19\" \"D:\\Official\\2019-20\" \/e \/xf *<\/pre>\n<ul>\n<li><code>\/e<\/code> &#8211; Copy subdirectories, including Empty ones.<\/li>\n<li><code>\/xf *<\/code> &#8211; Excludes all files &#8212; denoted by the wildcard <code>*<\/code><\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10511\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/07\/copy-folder-structure-2.png\" alt=\"copy directory structure without files\" width=\"699\" height=\"386\" \/><\/p>\n<p><strong>Tip:<\/strong> If you want to exclude a particular folder(s), use the <code>\/xd<\/code> switch.<\/p>\n<div class=\"rp\"><strong>RELATED:<\/strong> <a href=\"https:\/\/www.winhelponline.com\/blog\/compare-two-directories-files-find-differences\/#sync_robocopy\">Compare and Synchronize Two Folders using Robocopy<\/a><\/div>\n<hr \/>\n<h3><a id=\"powershell\"><\/a>Using PowerShell<\/h3>\n<p>Using PowerShell, you can mirror a directory tree (without copying files) using the following command-line:<\/p>\n<pre>Copy-Item -LiteralPath \"D:\\Official\\2018-19\" -Destination \"D:\\Official\\2019-20\" -Recurse -Filter {PSIsContainer -eq $true}<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10512\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/07\/copy-folder-structure-3.png\" alt=\"copy directory structure without files\" width=\"699\" height=\"156\" \/><\/p>\n<p>That&#8217;s it. You&#8217;ve now replicated the directory structure under another base folder.<\/p>\n<div class=\"qt\">\n<h4>Replicate the directory structure on another computer<\/h4>\n<p>If you want to replicate the folder structure on another computer that&#8217;s not in a network, use one of the above methods in that system to mirror a directory tree.<\/p>\n<p>Then, zip the mirrored folder using File Explorer&#8217;s <strong>Share<\/strong> tab or via the right-click menu &#8212; <code>Send To \u2192 Compressed (zipped) folder<\/code> option.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10513\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/07\/copy-folder-structure-4.png\" alt=\"copy directory structure without files\" width=\"700\" height=\"289\" \/><\/p>\n<p>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.<\/p>\n<p>Alternately, use the <a href=\"#powershell_batch_file\">batch file method<\/a> below.<\/p>\n<\/div>\n<hr \/>\n<h3><a id=\"powershell_batch_file\"><\/a>Method 4: Using PowerShell (output a batch file)<\/h3>\n<p>Using PowerShell, you can get the list of folders and make a readymade batch file that can create the same directory structure when it&#8217;s run from the target computer.<\/p>\n<p>Start PowerShell and use the following command-line <strong>syntax<\/strong>:<\/p>\n<pre>(gci -Path \"folder_path\" -Directory -Name -Recurse) | foreach-object {\"md `\"\" + $_ + \"`\"\"} | Out-File -FilePath \"output_file\" -Encoding [type]<\/pre>\n<h4>Example:<\/h4>\n<p>To get the list of directories under the <code>Backup\\Accounts<\/code> folder recursively and make a batch file, run the following command:<\/p>\n<pre>(gci -Path \"D:\\Backup\\Accounts\\\" -Directory -Name -Recurse) | foreach-object {\"md `\"\" + $_ + \"`\"\"} | Out-File -FilePath d:\\output.bat -Encoding UTF8<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-19891\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/05\/dir-list-to-bat-powershell.png\" alt=\"directory list structure batch file powershell\" width=\"700\" height=\"413\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignleft wp-image-9189\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/08\/information-icon.png\" alt=\"\" width=\"32\" height=\"32\" \/><em>PowerShell outputs to an <strong>ASCII<\/strong> file by default. It would be better to choose <strong>UTF8,<\/strong> especially if you have foreign characters in the folder names. In that case, replace <code>-encoding ASCII<\/code> to <code>-encoding UTF8<\/code> in the above command-line. Also, check out this SuperUser forum thread <a href=\"https:\/\/superuser.com\/questions\/1302096\/files-with-non-ascii-characters-in-file-name-in-a-windows-batch-file\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Files with non-ASCII characters in the file name in a Windows batch file<\/a> for the workarounds (<code>chcp<\/code> command) you can use when running the batch file.<\/em><\/p>\n<p>The <code>output.txt<\/code> in the above example is a batch file that creates the exact folder structure recursively.<\/p>\n<ol>\n<li>Transfer the batch file to the target computer.<\/li>\n<li>Rename the file with .bat extension &#8212; e.g., <code>output.bat<\/code><\/li>\n<li>Open a Command Prompt window on the target computer.<\/li>\n<li>Change to the base directory where you want the batch file to create the subfolders &#8212; e.g., <code>e:\\accounts<\/code>.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-19893\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/07\/dir-list-to-bat-powershell-replicate.png\" alt=\"directory list structure batch file powershell\" width=\"427\" height=\"214\" \/><\/li>\n<li>Run the file <code>output.bat<\/code> from that directory in the Command Prompt.<\/li>\n<li>Optionally, verify the parent folder&#8217;s properties dialog in the source as well as the destination.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-19892\" src=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/05\/dir-list-to-bat-powershell-verify.png\" alt=\"directory list structure batch file powershell\" width=\"546\" height=\"260\" \/><\/li>\n<\/ol>\n<p>That&#8217;s it. You&#8217;ve copied the folder structure on the target computer using batch file.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &#8230; <a title=\"Copy Folder Structure without Copying Files in Windows\" class=\"read-more\" href=\"https:\/\/www.winhelponline.com\/blog\/how-to-copy-folder-structure-without-copying-files\/\" aria-label=\"Read more about Copy Folder Structure without Copying Files in Windows\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[7],"tags":[106,396],"class_list":["post-10509","post","type-post","status-publish","format-standard","hentry","category-windows","tag-command-prompt","tag-powershell"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":3054,"url":"https:\/\/www.winhelponline.com\/blog\/move-copy-files-multiple-sub-folders-single-folder\/","url_meta":{"origin":10509,"position":0},"title":"How to Copy Files from Multiple Subfolders to a Single Folder?","author":"Ramesh","date":"May 1, 2016","format":false,"excerpt":"When importing photos from your camera or SD card via AutoPlay dialog using the Photos app, many sub-folders (month and year-wise) are created in the destination folder, which may not be what you wanted. Here is a step-by-step guide that explains how to move all files recursively from multiple subfolders\u2026","rel":"","context":"In &quot;Utilities&quot;","block_context":{"text":"Utilities","link":"https:\/\/www.winhelponline.com\/blog\/category\/utilities\/"},"img":{"alt_text":"iphone dcim","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/05\/iphone-dcim.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/05\/iphone-dcim.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/05\/iphone-dcim.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":5521,"url":"https:\/\/www.winhelponline.com\/blog\/error-0x80070091-directory-not-empty-deleting-folder-copying-chkdsk\/","url_meta":{"origin":10509,"position":1},"title":"Error 0x80070091 &#8220;The directory is not empty&#8221; When Deleting or Copying a Folder","author":"Ramesh","date":"October 15, 2017","format":false,"excerpt":"When you attempt to delete a folder or copy it to another location or drive, the following error may pop up: Interrupted Action. An unexpected error is keeping you from deleting the folder. If you continue to receive this error, you can use the error code to search for help\u2026","rel":"","context":"In &quot;Windows&quot;","block_context":{"text":"Windows","link":"https:\/\/www.winhelponline.com\/blog\/category\/microsoft\/windows\/"},"img":{"alt_text":"0x80070091 directory not empty","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2017\/10\/0x80070091_dir_not_empty.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":3766,"url":"https:\/\/www.winhelponline.com\/blog\/compare-two-directories-files-find-differences\/","url_meta":{"origin":10509,"position":2},"title":"How to Compare the Contents of Two Folders and Synchronize them","author":"Ramesh","date":"August 10, 2016","format":false,"excerpt":"Traditionally, Windows users have employed XCOPY or SyncToy to mirror copy a certain directory to a different location. If you're using Microsoft SyncToy, especially on Windows 10 or 11, it's possible that sometimes the files or folders may be missing in the destination, or the destination folder has extra files\u2026","rel":"","context":"In &quot;Utilities&quot;","block_context":{"text":"Utilities","link":"https:\/\/www.winhelponline.com\/blog\/category\/utilities\/"},"img":{"alt_text":"syncfolders - compare and sync files - task scheduler","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/08\/syncfolders-scheduler.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/08\/syncfolders-scheduler.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/08\/syncfolders-scheduler.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":8771,"url":"https:\/\/www.winhelponline.com\/blog\/find-and-delete-empty-folders-windows\/","url_meta":{"origin":10509,"position":3},"title":"How to Find and Remove Empty Folders in Windows","author":"Ramesh","date":"April 21, 2019","format":false,"excerpt":"Over time, hundreds of empty folders and junk files may take up your hard disk. While the junk files occupy disk space and can be cleaned up using Disk Cleanup or Storage settings, the empty directories remain. The empty folders don't take up disk space, but to organize your data\u2026","rel":"","context":"In &quot;Utilities&quot;","block_context":{"text":"Utilities","link":"https:\/\/www.winhelponline.com\/blog\/category\/utilities\/"},"img":{"alt_text":"find and delete empty directories using searchmyfiles utility","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/04\/searchmyfiles_find_empty_folders_1.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/04\/searchmyfiles_find_empty_folders_1.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2019\/04\/searchmyfiles_find_empty_folders_1.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":4883,"url":"https:\/\/www.winhelponline.com\/blog\/deskthemepack-extract-themepack-wallpapers-windows\/","url_meta":{"origin":10509,"position":4},"title":"Extract Wallpapers from DeskThemePack and ThemePack Files","author":"Ramesh","date":"December 19, 2016","format":false,"excerpt":"This article shows you different ways of extracting wallpaper images from a theme pack file in Windows. A theme is a combination of desktop background pictures, window colors, and sounds. Windows themes come in the form of theme packs. Theme packs are essentially CAB files that enclose resources such as\u2026","rel":"","context":"In &quot;Windows&quot;","block_context":{"text":"Windows","link":"https:\/\/www.winhelponline.com\/blog\/category\/microsoft\/windows\/"},"img":{"alt_text":"extract wallpapers from themepack and deskthemepack","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/12\/themepack-extract-4.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/12\/themepack-extract-4.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/12\/themepack-extract-4.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":4261,"url":"https:\/\/www.winhelponline.com\/blog\/print-directory-contents-using-chrome-firefox\/","url_meta":{"origin":10509,"position":5},"title":"How to Print Directory Contents Using Different Methods","author":"Ramesh","date":"October 4, 2016","format":false,"excerpt":"You can copy folder contents by selecting all items in a folder, pressing Shift key and clicking the Copy as Path command in the right-click menu. Then open Notepad or any other text editor and paste the contents from the clipboard. But if you need to print the directory list\u2026","rel":"","context":"In &quot;Windows&quot;","block_context":{"text":"Windows","link":"https:\/\/www.winhelponline.com\/blog\/category\/microsoft\/windows\/"},"img":{"alt_text":"get directory listing - sysexporter","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/10\/dir-list-sysexporter.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/10\/dir-list-sysexporter.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/10\/dir-list-sysexporter.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/10\/dir-list-sysexporter.png?resize=700%2C400&ssl=1 2x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/posts\/10509","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/comments?post=10509"}],"version-history":[{"count":0,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/posts\/10509\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/media?parent=10509"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/categories?post=10509"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/tags?post=10509"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}