12

I want to use robocopy to move a large number of files, except those that are in a whitelist. The whitelist contains approximately 150 files of different names. When I copy-and-paste the whitelist's filenames into the command line (using the /xf parameter), robocopy truncates the list.

c:\test> robocopy src dest *.ext /xf exclude1.ext exclude2.ext exclude3.ext ... exclude 299.ext exclude300.ext

Results in:

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

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

  Started : Fri May 24 14:09:31 2013

   Source : C:\test\src\
     Dest : C:\test\dest\

    Files : *.ext

Exc Files : exclude1.ext
            exclude2.ext
            exclude3.ext
            ....
            ....
            exclude200.ext
            exclude201.ext
            exclu

and then:

'exclude250.ext' is not recognized as an internal or external command,
operable program or batch file.
'exclude251.ext' is not recognized as an internal or external command,
operable program or batch file.
'exclude252.ext' is not recognized as an internal or external command,
operable program or batch file.
'exclude253.ext' is not recognized as an internal or external command,
operable program or batch file.

Unfortunately the files in the whitelist are hand-picked and can't be filtered by wildcards.

Is there a way to get around this?

1
  • This accepted answer has the highest point value (which is good). However, after three years (in 2016), @fara-importanta added an answer suggesting the job file, and included a quick, but very usable mention of that files syntax. see serverfault.com/questions/510482/…
    – ElderDelp
    Commented Oct 6, 2021 at 16:40

3 Answers 3

14

There is a limit on command line length (I think it is something like 2048 characters) in windows.

You should generate a job file with a small subset of the exclusion list specified (using the /save:filename argument) to get the syntax, edit the file to include the full list, and then use the /job:filename argument to run it.

For reference, the documentation for this tool can be found here.

1
  • This accepted answer has the highest point value (which is good). After three years, @fara-importanta added an answer suggesting the job file, and included a quick, but very usable mention of that files syntax. see serverfault.com/questions/510482/…
    – ElderDelp
    Commented Oct 6, 2021 at 16:37
3

Turns out that the robocopy job file syntax is not that complicated.

For your specific situation you can achieve what you want by creating a robocopy job file with the following content:

/XD
exclude1.ext
exclude2.ext
exclude3.ext
....

If you'd want to do the same for files too, then your robocopy job file would look like this:

/XD
exclude1.ext
exclude2.ext
exclude3.ext
....

/XF
file1.ext
file2.ext
file3.ext
....

By using the same logic you can move any other options from the command line to the job file.

1
  • Thank you for the syntax of the job file. I could not find it elsewhere. I put a link to this answer in the comments of the accepted answer.
    – ElderDelp
    Commented Oct 6, 2021 at 16:39
-1

try using wildcards after the /XF filename1*.ext filename2*.ext filename3*.ext This will only work if you know that the filename is unique in the entire structure. You may change the naming convention of the files you want to exclude to get around this limitation.

You must log in to answer this question.

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