Why does Robocopy ignore the /copy flags?

5

Robocopy Copy Flags?

I just recently made an answer here https://stackoverflow.com/a/15211788/891976 where I suggested using robocopy and its /copy flags, but for some as of yet unknown reason, the /copy flags are being ignored.

This was originally noted by dbenham, but I too have confirmed that when I specified the /copy:DA flag, robocopy just ignored it and did a full DAT copy.

Robocopy Documentation

Script

@echo off
robocopy Tools Tolls /COPY:DA /S /IS
pause >nul

Output

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

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

  Started : Mon Mar 04 16:59:43 2013

   Source : C:\Users\Username\Desktop\Tools\
     Dest : C:\Users\Username\Desktop\Tolls\

    Files : *.*

  Options : *.* /S /COPY:DAT /IS /R:1000000 /W:30

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

          New Dir          5    C:\Users\Username\Desktop\Tools\
100%        New File                 825        Connect.bat
100%        New File                 424        DevSpec.bat
100%        New File                 215        Disconnect.bat
100%        New File               69599        Shortcuts.zip
100%        New File              28.8 m        Tools.zip

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

               Total    Copied   Skipped  Mismatch    FAILED    Extras
    Dirs :         1         1         0         0         0         0
   Files :         5         5         0         0         0         0
   Bytes :   28.87 m   28.87 m         0         0         0         0
   Times :   0:00:00   0:00:00                       0:00:00   0:00:00


   Speed :           150632582 Bytes/sec.
   Speed :            8619.265 MegaBytes/min.

   Ended : Mon Mar 04 16:59:43 2013

Anyone have insight into why the /copy flag did not work?

David Ruhmann

Posted 2013-03-04T23:09:59.337

Reputation: 1 199

@DavidRuhmann, Any way that we can get our hands on the source code or actual workings? – Pacerier – 2015-04-24T17:10:38.257

@Pacerier, There is no available of the robocopy source code that I know about. – David Ruhmann – 2015-04-27T14:32:47.253

What timestamp should robocopy use if you don't specify the T flag? – None – 2013-03-04T23:13:18.167

1@AbqBill - The assumption would be the current system timestamp. – dbenham – 2013-03-04T23:16:54.290

@AbqBill I am just making an assumption since the functionality appears to be undocumented, but if you do not copy the time stamps, then it would seem to make sense to use the current time. However, I am unable to even verify this since it is ignoring my /copy flags. – David Ruhmann – 2013-03-04T23:17:09.193

I don't know the answer, but my guess is that it assumes T if you specify A or D. Experiment and see. – None – 2013-03-04T23:23:34.387

@AbqBill Indeed I am trying many different combinations. So far /COPY:DT works, /COPY:A works, but when I just specify /COPY:D is automatically appends the T. So far it appears to make the T required when D is used. I am trying to figure it out, but any insight to the undocumented behavior is appreciated. – David Ruhmann – 2013-03-04T23:26:34.037

This may be an implementation side-effect. I'm not sure the author(s) anticipated your use case. If you really need to use the current time after copying, this is pretty easily accomplished using PowerShell. – None – 2013-03-05T01:11:40.907

2@AbqBill Side-Effect or not it is undocumented behavior since the documentation gives all indication that this is a valid use case. Therefore, it could also be classified as a bug in design. For it supports a DA option for the DCOPY but not the COPY. That is a very inconsistent implementation, that has a need to be documented. – David Ruhmann – 2013-03-05T02:52:39.607

This behavior is as designed and documented. See my answer below for documentation. – Kevin Fegan – 2013-05-22T11:21:18.460

@KevinFegan This behavior is not documented in an current official documentation. XP010 is 17 version / 10 years old. So should I scour all of Java 1.4 documentation and say that is more correct over the Java 1.7 documentation when I am using version 1.7? – David Ruhmann – 2013-05-22T21:50:10.530

Answers

3

Undocumented Behavior

Well it would appear the undocumented behavior is as follows:

Whenever, the D flag is used for /COPY, robocopy will automatically add the T flag.

However, this does not apply to the directory /DCOPY flag. It can be specified without T and work.

Tested (no files are copied without D, only folders)

/Copy:D becomes /Copy:DT
/Copy:A becomes /DCopy:DA /Copy:A
/Copy:T becomes /DCopy:D /Copy:T
/Copy:DT becomes /DCopy:D /Copy:DT
/Copy:AT becomes /DCopy:DA /Copy:AT

Note: tested on Windows 7 64 bit and Windows 8 64 bit.

David Ruhmann

Posted 2013-03-04T23:09:59.337

Reputation: 1 199

@KevinFegan, And so how do we check which version our Robocopy is using? – Pacerier – 2015-04-24T17:24:26.753

@Pacerier - 1) Using Windows Explorer (explorer.exe), navigate to your copy of Robocopy.exe. Mine is located in "C:\Windows\System32\Robocopy.exe". 2) Right-click on "Robocopy.exe" and select "Properties". 3) Go to the "Details" Tab and look for "File version:", and "Product version:". For mine (Windows 7 x64), I have: "File version: 5.1.10.1027", and "Product version: XP027". – Kevin Fegan – 2015-04-25T23:44:12.363

1@KevinFegan Something to note, it would seem that Microsoft has dropped the XP0## version notation. On Windows 8.1, I only see 6.3.9600.17415 as both the File and Product version. – David Ruhmann – 2015-04-27T14:35:51.683

How would you specify /DCOPY without including T, and what would it mean? The only (documented) valid option to /DCOPY is T (so only /DCOPY:T). See the Command line reference here: Updated: April 17, 2012. Particularly the D option seems meaningless with /DCOPY... how would (should) the behavior of /DCOPY:DT be different than /DCOPY:T?

– Kevin Fegan – 2013-05-22T11:11:26.340

*...Well it would appear the undocumented behavior is as follows...* this is *documented* behavior. See the documentation here: XP010

– Kevin Fegan – 2013-05-22T11:24:19.143

I'm curious, Is this document still provided by an official Microsoft source? Also this document is about 17 version / 10 years old. Yet, the behavior is still undocumented in all the current official documentation. – David Ruhmann – 2013-05-22T21:41:13.680

*'... Is this document still provided by an official Microsoft source?'* Yes, while 10 years old, it is the most current full official Microsoft documentation available for Robocopy. It is currently available as Robocopy.doc for XP010 version when you download the current version of Robocopy GUI. (Note: Robocopy GUI includes version XP026 of Robocopy.exe and version XP010 of Robocopy.doc).

– Kevin Fegan – 2013-05-24T06:01:03.710

2

This is by design, and also it is not undocumented.

According to the Robocopy Documentation:

Note: If file Data is copied, then file Timestamps are also copied.

This is from page 6 in this document: XP010


About the XP010 document linked above:

While 10 years old, as of the date of this posting, it is the most current full official Microsoft documentation available for Robocopy. It is currently available as Robocopy.doc for XP010 version when you download the current version of Robocopy GUI from Microsoft website. (Note: Robocopy GUI includes version XP026 of Robocopy.exe and version XP010 of Robocopy.doc).

As of the date of this posting, no (printed or electronic/downloadable) full official Microsoft documentation is available for Robocopy version XP026 or XP027.

Kevin Fegan

Posted 2013-03-04T23:09:59.337

Reputation: 4 077

@david-ruhmann Interesting - I was not aware of the Robocopy documentation on TechNet. However, it is much less detailed than the XP010 version of the document. The explanation of the commands in XP010 missing from the TechNet document is extremely helpful! Still, I have read that document dozens of times, but never noticed that note on page 6, nor the sentence on page 20: However, if file data is copied, file timestamps are also copied. – GlennFromIowa – 2017-11-22T17:39:23.793

Interesting, So the only mention of it is in a document from 2003 for version XP010. But it is undocumented in all current official documentation. Windows 7 Version = XP027. – David Ruhmann – 2013-05-22T21:35:54.097

1*'...this document is about 17 version old...'* actually 2 versions old. After XP010 was version XP026 then XP027. The document I linked, while 10 years old, is the most current full official Microsoft documentation available for Robocopy. – Kevin Fegan – 2013-05-24T01:10:38.280

1

Again, Interesting. The only place where this document was released was through a TechNet blog (November 2006) with the release of a tool "RoboCopy GUI" (Abandonware). And incorrect, that document is not the most current full official Microsoft documentation. This is: http://technet.microsoft.com/en-us/library/cc733145.aspx or this robocopy /?. Also note that this tool is not by the official robocopy owners but a MSN Search group worker.

– David Ruhmann – 2013-05-24T17:07:24.713