11

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?

3 Answers 3

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.

3
  • 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, 2012 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 for the transcript of a test. Sep 20, 2012 at 22:00
  • 1
    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, 2012 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

3

From the robocopy reference page at ss64.com (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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .