How do I use Robocopy to exclude ALL subfolders under a chosen folder?
Solution 1:
Excluding subfolders is actually the default behavior of robocopy, or at least the version that comes with Windows 7. (In order to copy the sub-directories you would have to add the /S
or /E
option to the command.)
So, you can just use robocopy source-folder target-folder
.
Solution 2:
I've never done this, so this will be kind of a guess:
/lev:0
Copies only the top N levels of the source directory tree.
/xd *
Excludes directories that match the specified names and paths.
Reference: http://technet.microsoft.com/en-us/library/cc733145(v=ws.10).aspx
Solution 3:
From the robocopy
reference page at ss64.com (which you may wish to bookmark, I have):
-
>/LEV:n : Only copy the top n LEVels of the source tree.
(LEV:0
is what you're looking for, it will copy 0 folders down in the tree from the directory where you target it, so only the files in the folder you target.) -
/XD dirs [dirs]... : eXclude Directories matching given names/paths.
- also an exclude files switch,
/XF file [file]... : eXclude Files matching given names/paths/wildcards.
if that's really what you're after.
- also an exclude files switch,