Robocopy Version XP010 - Excluding Multiple Directories using /XD

I'm attempting to use Robocopy to routinely copy data between 2 servers. In the file structure being copied there are several folders + their associated sub-folders e.g DfsrPrivate and Projects\Archived for this exampleI don't want to copy.

I've attempted to use the switches /XDDfsrPrivate /XD Projects\Archived

/XF is also used to exclude all .bak files. (referenced after the 2 /XD switches)

This results in the log file header below:


-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows :: Version XP010
-------------------------------------------------------------------------------

Started : Wed Dec 05 00:51:28 2007

Source : \\[Servername]\Data\
Dest : D:\Data\

Files : *.*

Exc Files : *.bak

Exc Dirs : DfsrPrivate
Projects\Archived


Options : *.* /S /E /COPYALL /ZB /MAXAGE:1 /R:10 /W:30

------------------------------------------------------------------------------

This results in theDfsrPrivate being excluded butProjects\Archived and all the subfolders below arenot.

Has any one had experience with trying this, and had success?
December 5th, 2007 7:35am

Try: /XD *"DfsrPrivate" *"Projects\Archived"
Free Windows Admin Tool Kit Click here and download it now
February 21st, 2008 10:24am

I can confirm that the robcopy /XD switch works great, even with the /Purge switch. This way robocopy will not put lots of Access Denied entries in your robocopy log file for the DFS replication private folder DfsrPrivate and all it's sub folders.

Here's my example robocopy script using the /XD switch:

Set Source=\\okrs0172\ghost$
Set Destination=\\okrsvh0100\ghost$
Set LogFile=C:\Logs\Base_Image_OKR.txt

rem copy _Base and Drivers folders for DFS replication which starts with OKRSVH0100

robocopy %Source%\_Images\XP\_Base %Destination%\_Images\XP\_Base /z /e /np

/XD DfsrPrivate /purge /r:10 /w:30 /log:%LogFile%

Enjoy,

ZippyD

April 17th, 2008 8:05pm

You both missed his point; he has a two-part pathof "Projects\Archived"

Yes, one-part paths (ie. actual dir names) work fine (as the OP stated). However, when you don't want all instances of "Archived" to be excluded (just the instance in the "Projects" folder), robocopy does not work as advertised.

BTW, jimahs, you should try your recommendations before posting, as *"Projects\Archived" causes robocopy to puke:

ERROR : Invalid Parameter #nn : "*Projects\Archived" (yes, even though I placed the asterisk prior to the opening quote, it shows up to the right of the opening quotein the error message)

Does anyone out there have any *real* solutions?

Free Windows Admin Tool Kit Click here and download it now
July 5th, 2008 6:27pm

I have found that multi-part paths can be excluded if they are fully qualified, for example:

c:\Projects\Archived

September 8th, 2008 7:43pm

I haven't found this - e.g. /XD D:\Testing\Source\DirA\Subdir1 - this switch still results in a DirA\Subdir1 being created and populated with files in my destination.
Free Windows Admin Tool Kit Click here and download it now
September 10th, 2008 12:25am

Using version XP010 of RoboCopy, I was able to copy a root share and exclude multiple folders with one command. The folders I wanted to exclude had common names, so I opted to use full paths. This is my XD switch:

Code Snippet

/XD G:\RootShare\Level1\SomeFolder "G:\RootShare\Level1\Folder with Spaces" "G:\RootShare\Level4\Some Other Folder"

Use the /L switch for testing.....with this /L switch I ran a full test copy of the root share in 60 seconds, for 1TB of data.
October 2nd, 2008 6:53pm

I agree... the full path relative or mapped, and use ""
ie /XD "\\server\share\share\" "\\server\share2\share" "\\and so on and so on"
works great.. if you are not sure use /l to generate a list and review b4 you run
Free Windows Admin Tool Kit Click here and download it now
December 1st, 2008 5:38pm

I have the same problem too on Windows 2003.  I can only exclude the first of 2 long directories with spaces in the path.

 

  • Proposed as answer by biggigunn Friday, January 25, 2013 4:10 PM
June 30th, 2011 9:24pm

@JS2010, You should put the directories in quotes.

robocopy %source% %destination% /COPYALL /S /XD "C:\MyDirs\ExcludeDir1" "c:\MyDirs\ExcludeDir2" "c:\MyDirs\ExcludeDir3"


Free Windows Admin Tool Kit Click here and download it now
July 14th, 2011 5:23pm

I'm seeing the same behavior as the OP, and the quotes don't work (windows 2008 R2 server)

My output file looks like this;


-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows                             
-------------------------------------------------------------------------------

  Started : Mon Aug 15 15:17:29 2011

   Source : \\tsclient\C\test\
     Dest : C:\test\

    Files : *.*
    
 Exc Dirs : "c:\test\content\uploads\"
     "\\tsclient\c\test\content\uploads"
    
  Options : /JOB *.* /S /E /COPY:DAT /PURGE /MIR /R:1000000 /W:30

------------------------------------------------------------------------------

                    1 \\tsclient\C\test\
                    1 \\tsclient\C\test\content\
                    1 \\tsclient\C\test\content\uploads\
   *EXTRA File          0 blah - Copy - Copy.bmp
   *EXTRA File          0 blah - Copy.bmp

------------------------------------------------------------------------------

 

It should entirely ignore the \content\uploads folder (I've excluded both the source and the dest instances of that folder) - instead it consistently whacks my files

 

August 15th, 2011 7:20pm

I believe the problem lies within the "\" at the end of the source and destination directories.  I was able to successfully run a directory exclusion with something similar to the below:

C:\Downloads\robocopy.exe "E:\Working\Data" "C:\Users\Data\Documents" /E /R:3 /W:5 /V /ETA /XD "E:\Working\Data\My Pictures" "E:\Working\Data\My Videos" "E:\Working\Data\My Music"

 

This successfully copied the contents of an XP "My Documents" Folder while excluding the pictures, videos, and music folders.

 

Free Windows Admin Tool Kit Click here and download it now
October 19th, 2011 4:57pm

Using the /XD or /XF parameter in a RoboCopy JOB file, utter failure.

Complained of a bad parameter on line where the /XD resided. 

Same exact parameters at the command line, worked fine.  Kind sucked that i wasted yet another Saturday to do this the correct, repeatable, and automated way, but something messed up with robocopy jobs killed it. 

March 19th, 2012 2:44am

to exclude directorie use this.

/xd dfsrprivate Archived 

this should exclude any folders with the name DFSRPrivate, along with any folders names Archived.

however is there are some Archived folders you want to back up & others you do not, then you will have to put the path to the ones you do not in the /XD switch.

ex..

robocopy D:\example \\example\example /XD DFSRPRivate D:\projects\Archived

you do not need to state more then 1 /XD switch, just use a space between your folders you want to exclude. also anyfolder pats that have spaces in the name (ie D:\Projects\Archived data) you must contain the folder between 2 quotes (ie "D:\Projects\Archived data")

  • Proposed as answer by Steve_Lindsey Friday, September 21, 2012 2:49 PM
Free Windows Admin Tool Kit Click here and download it now
September 21st, 2012 2:49pm

I had the same problem with my robocopy script, an example of what I had before is below:

robocopy C:\Folders C:\Temp /E /MINAGE:31 /R:1 /W:5 /L /XD "C:\Folders\Subfolder1" "C:\Folders\Subfolder2"

I have found that my script works by removing the full path from the exclude command as follows:

robocopy C:\Folders C:\Temp /E /MINAGE:31 /R:1 /W:5 /L /XD "Subfolder1" "Subfolder2"

This successfully excludes the subfolders mentioned and all subsequent sub folders within them (for example "C:\Folders\Subfolder1\TEST" and "C:\Folders\Subfolder1\TEST2" etc)

Hope this helps.



  • Edited by RainhamWolf Friday, April 05, 2013 1:30 PM
  • Proposed as answer by T_Bagger Saturday, May 18, 2013 3:08 PM
  • Unproposed as answer by T_Bagger Saturday, May 18, 2013 3:08 PM
  • Proposed as answer by T_Bagger Saturday, May 18, 2013 3:09 PM
April 5th, 2013 1:29pm

I am using ROBOCOPY XP027 - Comes with W7

The /XD switch in the command line works fine, not so in the job:

THIS WORKS FINE:

             ROBOCOPY /XD DIR1 DIR2 DIR3

THIS DOES NOT WORK

             ROBOCOPY /job:TEST1
.......
TEST1.RCJ

/XD
      DIR1
      DIR2
      DIR3

any clue is welcome


  • Edited by Cap Kirk 01 Sunday, August 18, 2013 5:11 PM
Free Windows Admin Tool Kit Click here and download it now
August 18th, 2013 5:10pm

I am using ROBOCOPY XP027 - Comes with W7

The /XD switch in the command line works fine, not so in the job:

THIS WORKS FINE:

             ROBOCOPY /XD DIR1 DIR2 DIR3

THIS DOES NOT WORK

             ROBOCOPY /job:TEST1
.......
TEST1.RCJ

/XD
      DIR1
      DIR2
      DIR3

any clue is welcome


I typically dont call upon job files, as i never need them.

however, i think that you may need to be a bit more granular with the job, IE, try to list the full path to the file.

Also what error msg does Robocopy throw at you?

October 22nd, 2013 7:54pm

Using quotes around pathnames is essential. If you have a space issue, and if the server supports it, use the short names of the directories. To access, add the "/X" parameter to a "dir" command, as in:

     C:\>dir /x
      Volume in drive C is Operating System
      Volume Serial Number is BEG2-DIFF
    
      Directory of C:\
     ...
     01/10/2014  10:32 AM    <DIR>          PROGRA~1     Program Files
     12/13/2013  03:44 PM    <DIR>          PROGRA~2     Program Files (x86)
     09/26/2013  07:54 AM    <DIR>          R_FUNC~1     R_Functions
     ...    

Now you know you can refer to "program files" as PROGRA~1 and "program files (X86)" as PROGRA~2 - with or without quotes.

Free Windows Admin Tool Kit Click here and download it now
January 10th, 2014 10:30pm

I am using ROBOCOPY XP027 - Comes with W7

The /XD switch in the command line works fine, not so in the job:

THIS WORKS FINE:

             ROBOCOPY /XD DIR1 DIR2 DIR3

THIS DOES NOT WORK

             ROBOCOPY /job:TEST1
.......
TEST1.RCJ

/XD
      DIR1
      DIR2
      DIR3

any clue is welcome


This works fine, DO NOT put any quotes eg:

--------------------------------

 /XD  
    c:\users\user1\AppData\Local\Microsoft\Windows\Temporary Internet Files
    c:\Users\user1\AppData\Local\Temp
    c:\$Recycle.Bin
    c:\MSOCache
    c:\Nvidia
    c:\Perflogs
    c:\Program Files
    c:\ProgramData
    c:\Recovery
    c:\System Volume Information
    C:\SysInternals
    C:\VirtDub
    C:\Windows
    C:\Users\Administrator
    C:\Users\Classic .NET AppPool
    C:\Users\DefaultAppPool
    C:\Users\DefaultAppPool.IIS APPPOOL
    C:\Users\Public
    C:\Users\UpdatusUser
    :: eXclude Directories matching given names/paths.

--------------------------------

note the spaces in the Bold lines, all these folders were excluded with Robocopy which is on Windows 7 file version 5.1.10.1027.

When I tried it with Quotes, everything was being copied.


  • Edited by ShandyT Saturday, May 31, 2014 11:40 AM
May 31st, 2014 11:39am

I am using ROBOCOPY XP027 - Comes with W7

The /XD switch in the command line works fine, not so in the job:

THIS WORKS FINE:

             ROBOCOPY /XD DIR1 DIR2 DIR3

THIS DOES NOT WORK

             ROBOCOPY /job:TEST1
.......
TEST1.RCJ

/XD
      DIR1
      DIR2
      DIR3

any clue is welcome



Robocopy requires a new parameter for each excluded directory in the cli, so perhaps the job file requires the same?

/XD
      DIR1

/XD
      DIR2

/XD
      DIR3

I am not familiar with using RCJ files, but this is the correct syntax from the cli:

/XD DIR1 /XD DIR2 /XD DIR3


Anything in a robocopy command with a /PARAMETER behind it is assumed to be a named file that is to be copied, so when it encounters this it's saying "exclude DIR1 but copy DIR2 and DIR3":

/XD DIR1  DIR2  DIR3

 

Also network paths with spaces require a syntax which makes absolutely no sense:

/"\tsclient\C\users\/"

Free Windows Admin Tool Kit Click here and download it now
November 17th, 2014 8:51pm

Justin,

"it's saying "exclude DIR1 but copy DIR2 and DIR3":

/XD DIR1  DIR2  DIR3"

If you forgive me, that is incorrect.  However, if I am misunderstanding you, please forgive me.

I was having a devil of a time copying my files.  I wanted to copy docs.  In looking at the logs, I forgot that the shortcut to my music, pictures, and videos were in there, so it was erring on them.

"2015/09/12 22:53:43 ERROR 5 (0x00000005) Scanning Source Directory C:\Users\Me\Documents\My Music\
Access is denied."

I edited my script exactly that way, though I used quotes for everything (even tho you don't have to if there's no spaces, etc.) and I only wrote /XD once, and the 3 directories like so:

robocopy "C:\Users\Me\Documents" "D:\CBackup\Documents" /V /S /E /IS /r:3 /w:120 /XD "C:\Users\Me\Documents\My Music" "C:\Users\Me\Documents\My Pictures" "C:\Users\Me\Documents\My Videos" /LOG+:D:\robocopy.txt

As you can see, I only have "/XD" once, and it knew to exclude all 3 of those directories, not exclude 1 and copy the other 2 like you suggested.

-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows                             
-------------------------------------------------------------------------------

  Started : Sat Sep 12 22:56:03 2015

   Source : C:\Users\Me\Documents\
     Dest : D:\CBackup\Documents\

    Files : *.*
    
 Exc Dirs : C:\Users\Me\Documents\My Music
     C:\Users\Me\Documents\My Pictures
     C:\Users\Me\Documents\My Videos
    
  Options : *.* /V /S /E /COPY:DAT /IS /R:3 /W:120

------------------------------------------------------------------------------

This time, the command ran without hanging up on those 3 directories.

However, it WILL error if you don't use relative path's.  Allegedly, the documentation says ROBOCOPY only needs the directory if it exists in the source, so I should just need to do "My Music" "My Pictures"...  However, that didn't work for me.  I did indeed need to use the full paths.

HTH somewhat.

September 12th, 2015 11:28pm

That is so weird.  I had the exact OPPOSITE effect.

When I was copying from "C:\users\me\documents" and had /XD "My Music", it erred big time.  Kept telling me access denied, and did not list it in the excluded directories section of the summary.

When I did /XD "C:\users\me\documents\My Music" THEN it excluded "My Music" just fine.

I may have a diff version of RC, or haven't patched my windows or...Im a yo-yo :)

Anyway, I got mine working that way.

Free Windows Admin Tool Kit Click here and download it now
September 12th, 2015 11:35pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics