Copy a folder but exclude certain subfolders with robocopy
Use robocopy's /XD switch to skip named directories while copying a whole folder tree for backup.
01Command
$ robocopy "C:\Source" "D:\Backup" /E /XD "node_modules" ".git" "temp"02What it does
robocopy is ideal for folder backups, and /E copies every subfolder including empty ones. /XD takes one or more directory names and leaves them out of the copy entirely, wherever they appear in the tree. This keeps backups small by skipping caches and dependency folders such as node_modules.
03Risk
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- Robocopy - Robust file and folder copyEvidence: Documents /E (copy subfolders including empty ones) and /XD dirs (eXclude Directories matching given names/paths) in the robocopy switch list.
- robocopy (Windows Commands)Evidence: Official robocopy reference lists /e (copies subdirectories including empty ones) and /xd <directory>[ ...] (excludes directories matching the specified names or paths).
Last verified: 2026-09-19 · Category: Files & Folders
06Related solutions
Diagnose NTFS file system errors and bad sectors on any volume — including the system drive while Windows is running — before committing to a repair.
Robocopy is Windows' built-in robust file copier: use /MIR to keep a destination folder as an exact one-way mirror of a source, resumable and restartable.
Two-step command sequence that makes you the owner of a locked file tree and grants yourself full control — the standard fix for 'Access is denied' on old profiles and OS reinstall leftovers.