How to Copy a Folder Structure Without Files (Windows, Mac, Linux)
Recreate a folder tree in a new place and leave the files behind. One built-in command per operating system, each tested, plus the switch that quietly deletes things.
Quick Answer
To copy a folder structure without files on Windows, run robocopy "C:\Source" "D:\Dest" /E /XF * in Command Prompt. On macOS and Linux, run rsync -a --include='*/' --exclude='*' /path/source/ /path/dest/. Both recreate every subfolder, including empty ones, and copy no files.
File Explorer and Finder cannot do this: copying a folder always brings its contents along. The usual reasons for wanting only the tree are reusing last year's project or client layout, preparing the destination before a migration, or sharing how a drive is organized without sharing what is on it. Every command below was run on a test tree with nested, empty, and hidden folders and names containing spaces.
| System | Command | Good to know |
|---|---|---|
| Windows | robocopy src dst /E /XF * | Keeps hidden folders and attributes; has a preview switch |
| Windows | xcopy src dst /T /E /I /H | Shorter, but skips empty and hidden folders without /E and /H |
| Windows | PowerShell Get-ChildItem -Directory | Easy to filter or script |
| macOS, Linux | rsync -a --include='*/' --exclude='*' | Keeps permissions and dates; works over SSH |
| macOS, Linux | find + mkdir -p | No rsync needed; easy depth limit |
Windows: Robocopy (Recommended)
Robocopy ships with Windows 10 and 11. Two switches turn it into a folders-only copy:
robocopy "C:\Source" "D:\Dest" /E /XF */Ecopies all subfolders, including empty ones. (/Swould skip empty folders, and with every file excluded that means almost nothing gets created.)/XF *excludes every file, so only the directories are left to copy.
The destination folder is created if it does not exist, hidden folders are included, and each new folder keeps the attributes of the original. To see what would happen before anything is created, add /L (list only):
robocopy "C:\Source" "D:\Dest" /E /XF * /LUseful additions:
/DCOPY:DATalso copies each folder's timestamps, so the new tree keeps the original created and modified dates./LEV:2limits the depth. The source folder itself is level 1, so/LEV:2copies only the top-level subfolders and/LEV:3goes one level deeper./XD "Archive" "node_modules"leaves named folders (and everything under them) out.
Robocopy returns an exit code below 8 when it succeeds. That matters only in batch files, where a non-zero code is not necessarily an error.
Windows: Xcopy
Xcopy has a switch made for this job. /T creates the directory structure and copies no files:
xcopy "C:\Source" "D:\Dest" /T /E /I /HAll three extra switches fix something that otherwise goes wrong:
/E: without it,/Tsilently skips empty folders, and after a folders-only copy every folder is empty./I: without it, xcopy stops and asks whether a destination that does not exist yet is a file or a directory./H: without it, hidden folders are left out.
New folders get the current date and default attributes. If you need the original dates or a preview, use robocopy.
Windows: PowerShell
PowerShell is the better choice when you want to filter which folders are recreated. This version works in Windows PowerShell 5.1 and PowerShell 7:
$src = 'C:\Source'
$dst = 'D:\Dest'
Push-Location -LiteralPath $src
Get-ChildItem -Recurse -Directory -Force |
Resolve-Path -Relative |
ForEach-Object { New-Item -ItemType Directory -Force -Path (Join-Path $dst $_) | Out-Null }
Pop-Location-Directory returns folders only, -Force includes hidden ones, and Resolve-Path -Relative turns each one into a path relative to the source so it can be rebuilt under the destination. To recreate only some folders, add a filter after Get-ChildItem, for example | Where-Object FullName -notmatch '\\Archive(\\|$)'. More listing options are in the Get-ChildItem guide.
Want the structure as a document instead of a copy? tree "C:\Source" /a > structure.txt writes it to a text file; see the tree command guide.
Mac and Linux: rsync and find
rsync
rsync is preinstalled on macOS and on most Linux distributions. Include every directory, exclude everything else:
rsync -a --include='*/' --exclude='*' /path/source/ /path/dest/The order of the two rules matters: rsync uses the first rule that matches, so directories (names ending in /) are kept before --exclude='*' drops the rest. The trailing slash on source/ means “the contents of source”; leave it off and you get dest/source/... instead. -a preserves permissions and modification times. Add -n -v for a dry run that lists the folders without creating them. The destination can be remote, as in user@server:/path/dest/.
find + mkdir
If rsync is not available, list the directories and create them on the other side:
mkdir -p /path/dest
(cd /path/source && find . -type d -print0) | (cd /path/dest && xargs -0 mkdir -p)-print0 and xargs -0 keep folder names with spaces or quotes intact. To copy only the first two levels, add -maxdepth 2 right after find .. The new folders get default permissions and today's date; use rsync when those need to match.
Robocopy /MIR: Read This Before You Use It
Many guides suggest robocopy src dst /MIR /XF * to “mirror the folder tree”. /MIR is /E plus /PURGE: it makes the destination match the source by deleting whatever the source does not have.
What happened in our test
With /MIR /XF *, a folder that existed only in the destination was deleted along with the file inside it. A stray file sitting in a folder that exists on both sides was left alone. So /XF * does not protect files inside folders that get purged.
Use /MIR only when the destination is new or you really want extra folders removed, and run it with /L first: lines marked *EXTRA Dir and *EXTRA File are what would be deleted. For a plain folders-only copy, /E /XF * never deletes anything.
Verify the Copy
Two quick checks: no files came across, and the two trees have the same folders.
Windows (Command Prompt, then PowerShell):
:: Should print "File Not Found"
dir /s /b /a-d "D:\Dest"function Get-Tree($p) {
Push-Location -LiteralPath $p
Get-ChildItem -Recurse -Directory -Force | Resolve-Path -Relative
Pop-Location
}
Compare-Object (Get-Tree 'C:\Source') (Get-Tree 'D:\Dest')macOS and Linux:
find /path/dest -type f | wc -l # should print 0
diff <(cd /path/source && find . -type d | sort) <(cd /path/dest && find . -type d | sort)No output from Compare-Object or diff means the folder trees are identical.
When the Files Follow Later
An empty tree is often step one of a bigger move: the structure goes first, the files are copied or sorted into it afterwards. That second step is where things get lost, and a folder count will not catch a file that was skipped or cut short.
- Small folders, no install: the free Folder Compare tool takes two folders (up to 100 files and 50 MB each), hashes them in memory on our server without storing them, and lists missing, added, and changed files.
- Whole drives: FolderManifest is a desktop app for Windows 10/11, macOS, and Linux that compares the source and the destination by SHA-256 on your own machine and exports the result as an HTML, CSV, or Markdown report. It can also sort loose files into folders from a plan you review first, with undo.
To be clear about the limits: FolderManifest does not have a “copy folders only” button. For that, the commands above are the right tool and they are free. It earns its place after the files have moved, when you need proof that everything arrived. The Windows walkthrough is in compare two folders on Windows.
Frequently Asked Questions
How do I copy a folder structure without files in Windows?
Open Command Prompt and run robocopy "C:\Source" "D:\Dest" /E /XF *. The /E switch copies every subfolder, including empty ones, and /XF * excludes all files, so only the folder tree is created. The older equivalent is xcopy "C:\Source" "D:\Dest" /T /E /I.
Can File Explorer or Finder copy folders without their files?
No. Neither File Explorer on Windows nor Finder on macOS has a "folders only" copy option. Use a command instead: robocopy or xcopy on Windows, rsync or find with mkdir on macOS and Linux.
What is the difference between xcopy /T and xcopy /T /E?
xcopy /T creates the folder structure but skips empty folders. Adding /E includes empty folders too, which is what most people want when they are copying a template. Add /H as well, or hidden folders are left out.
How do I copy a directory structure without files in Linux or on a Mac?
Run rsync -a --include='*/' --exclude='*' /path/source/ /path/dest/. The include rule matches every directory and the exclude rule drops everything else, so only the tree is copied. Without rsync, use find to list the directories and mkdir -p to create them.
Does robocopy /MIR /XF * copy only the folders?
It copies only the folders, but /MIR also purges the destination. In our test, a folder that existed only in the destination was deleted together with the file inside it. Use /E /XF * unless you specifically want extra destination folders removed.
How do I copy only the first level or two of folders?
With robocopy add /LEV:n, where the source folder itself counts as level 1, so /LEV:2 copies only the top-level subfolders. On macOS and Linux add -maxdepth to find, for example find . -maxdepth 2 -type d.
How do I check that the copied structure matches the original?
List the folders on both sides as relative paths and compare the two lists. In PowerShell use Compare-Object; on macOS and Linux use diff on the output of find . -type d | sort. No output means the two trees are identical.
Prove Every File Arrived After a Move
SHA-256 folder comparison, saved manifests, and shareable reports for Windows, macOS, and Linux. 7-day free trial, no card required, 30-day money-back guarantee.
