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

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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
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 for the transcript of a test. – Ansgar Wiechers Sep 20 '12 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 '12 at 19:58

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.
share|improve this answer

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

share|improve this answer

Your Answer

 
discard

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.