I'm trying to use Robocopy in a way that excludes all subfolders under a chosen folder. In other words, I only want to target a folder and robocopy only the files within it but not it's subfolders. Is there a way to do so?
Asked
Active
Viewed 5.4k times
3 Answers
9
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
.

HopelessN00b
- 53,795
- 33
- 135
- 209

Tonny
- 6,332
- 1
- 18
- 31
-
1@HopelessN00b I actually tested this before I posted. It does work like that. (The version of robocopy that comes with W7.) – Tonny Sep 20 '12 at 21:51
-
1@HopelessN00b He's right. no-recursion is the default behavior at least for versions 6.1 (shipping with Windows 7) and XP010 (from the Windows Server 2003 Resource Kit). See [here](http://www.planetcobalt.net/robocopy.shtml) for the transcript of a test. – Ansgar Wiechers Sep 20 '12 at 22:00
-
1There are some big differences in robocopy versions between XP and Win7 and some subtle ones from version to version. Whenever I use robocopy in a script I make absolutely sure to call a specific version of the command. Never can tell which version would be called when going through %PATH%. – Tonny Sep 21 '12 at 19:58
5
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

pauska
- 19,620
- 5
- 57
- 75
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,

HopelessN00b
- 53,795
- 33
- 135
- 209