Robocopy is ignoring /xd directories

2

I am trying to use Robocopy to create client software builds by copying all the necessary files out of our main repository. We have multiple clients each needing their own custom software builds.

I have a list of requirements for each client's build. My thinking is to copy over the core stuff first (binaries and such, used by all clients) and then copy over the client specific stuff depending on for whom I'm making a build by making use of these lists. We have something like this already working with xcopy.

There is obviously a bunch of stuff I want excluded from the client build such as source files, log files and obviously all the client specific stuff. I thought by making clever use of the /xf and /xd switches I should be able to get it to work.

After a getting all the needed info, the following command is built in Lua:

robocopy "Z:\path\to\source" "../dest"  /e /xf *.cpp *.h *.hpp [[. . .]] *.cxx   /xd Data/Testing Data/Some/Client/Data Data/Other/Client/Data [[ . . .]] Data/More/Directories 

When running it I get the following output:

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

  Started : Tuesday, August 1, 2017 11:15:59 AM
   Source : Z:\path\to\source
     Dest : ../dest

    Files : *.*

Exc Files : *.cpp
        *.h
        *.hpp
        [[. . .]]
        *.cxx

 Exc Dirs : Data/Testing
        Data/Some/Client/Data
        Data/Other/Client/Data
        [[ . . .]]
        Data/More/Directories

  Options : *.* /S /E /DCOPY:DA /COPY:DAT /R:1000000 /W:30 

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

The output tells me my command is formatted properly and that Robocopy understands what I'm asking it to do.

The problem is that it's straight up ignoring the Exc dirs list and is just copying everything. I do not want to exclude the whole Data directory, but only the bits inside it that are relevant.

If I use back slashes (\) then the Exc dirs output is printed like Data\\testing. Could this be my issue?

getack

Posted 2017-08-01T11:33:28.380

Reputation: 121

Did you try to use absolute paths? Did you try to build a small example to see what kind of slashes you need? – Seth – 2017-08-01T11:43:16.133

I am trying to avoid absolute paths because the scripts must be able to run on any machine, with the repository installed anywhere. The script is part of the main repository, so we use relative paths then. I am building a small example now to test the theory of the slashes. – getack – 2017-08-01T11:47:10.010

If you don't want to use full explicit paths of the excluded then just use the sub folder name only of some top level subfolder name, etc. to tell the job to exclude i.e. /XD "Testing Data" "More" and that should work but for all subfolders matching that name so you may need to rethink the folder naming for the dirs you want to exclude and append a character to make them unique if the name is not unique otherwise per the job so "/z_Testing Data" for example. Otherwise, consider putting dirs to not backup in a standard top level parent folder e.g. \NoBackup\Testing Data. Simple to test. – Pimp Juice IT – 2017-08-01T12:39:09.150

Our repository is almost 20 years old. Changing the directory layout to something more sensible is unfortunately not possible due to technical inertia. – getack – 2017-08-01T13:29:04.137

I don't really get why you would not be able to use absolute paths. Your original question states you're generating the robocopy line using LUA and also already include an absolute path. But well, it seems you've found an answer that works for you. Interesting though that your XCOPY approach works as it should have the same behavior. Maybe exclude the full example of what you did in your answer, as it might be helpful. – Seth – 2017-08-02T05:53:38.870

Answers

0

robocopy is advertised as the replacement for xcopy but if it's unable to do something simple as what I want then it's truly a terrible replacement.

Any directory name after /xd that matches is excluded. This makes sense and it functions as advertised. Looks like any time you give it anything more than just a directory name then it wets the bed. My problem is surely not so unique looking at some of the other people on the internet and their troubles with robocopy.

I have the following directories:

C:\repo\SomeProject\Data             <- DONT exclude this
C:\repo\SomeOtherProject\Data        <- DONT exclude this
C:\repo\AnotherProject\bar           <- DONT exclude this
C:\repo\Data\foo                     <- Exclude this
C:\repo\Data\bar                     <- Exclude this
C:\repo\Data\baz                     <- DONT exclude this
  • If I call robocopy with /xd Data then C:\repo\SomeProject\Data and C:\repo\SomeOtherProject\Data will also be excluded
  • If I call robocopy with /xd foo bar then C:\repo\AnotherProject\bar will also be excluded.

I want to be able to call robocopy with /xd Data\foo Data\bar so that only foo and bar in Data will be excluded.

Absolute file paths will not work because the code must be portable and I don't really want to inject absolute paths for each entry in my >100 excludes list. It just doesn't seem right.

What appears to happen is if I use /xd Data\bar then robocopy interprets it as Data\\bar which it cannot find. I do not know why a single \ is changed to \\ and any permutation of \ or / does not work either.

The solution

So ultimately the answer to my question is to use xcopy. I give it a list containing entries such as *.cpp, 8.vcxproj, \Data\foo\, \Data\bar\ and a 100 other entries and it seems to work just fine excluding all the stuff I don't want while keeping the stuff I need.

getack

Posted 2017-08-01T11:33:28.380

Reputation: 121