Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

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.

share|improve this answer
@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
@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 for the transcript of a test. – Ansgar Wiechers Sep 20 '12 at 22:00
@AnsgarWiechers Well, holy hell, that is a shocker. It is definitely not the default in XP026(?), which is what I have installed on all my XP/2k3 stuff, or the version I have on 7/2008. All the years I've been using robocopy and the default behavior is... not what I thought at all? That can't be right... I shall have to investigate what;s causing the difference. Regardless, I'll be editing @Tonny 's answer a little so it looks better (and I change change my vote). Thanks to both of you for... this perplexing information. – HopelessN00b Sep 20 '12 at 23:57
There 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

I've never done this, so this will be kind of a guess:


Copies only the top N levels of the source directory tree.

/xd *

Excludes directories that match the specified names and paths.


share|improve this answer

From the robocopy reference page at (which you may wish to bookmark, I have):

  1. >/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.)
  2. /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.
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.