Take the 2-minute tour ×
Server Fault is a question and answer site for professional 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

4 Answers 4

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
    
@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
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

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

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

GSCopy Pro v6.0 (RoboCopy Alternative) with Open File Agent GSCopyPro is a single command-line tool (CLI) that can copy, replicate and move files from one folder to another. This folder can be on the same machine/ server or another server elsewhere. What makes GSCopyPro stand out from other competitors is the fact it works on 32-bit as well as 64-bit systems and has no restrictions. It can easily be scheduled to run as a scheduled task and fully automated. GSCopyPro also comes with an open file agent which can copy files that are locked/ opened by other processes. This feature is supported in all windows vSCersions from widows XP/ 2003 and later. Go To:>> http://www.gurusquad.com/GOPYPRO

share|improve this answer
    
This doesn't really answer the question of how to use Robocopy. Are you affiliated with the product? –  squillman Nov 6 '13 at 19:00

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.