13

Sorry, I know this sounds like a newbie question. But seriously, I'm an experienced developer, and I understand that Windows 7 Pro 64-bit and the like will say, "Oh, if you move an NTFS tree from one drive to another, when I write the children files that really means that I'm modifying the parent folder so I'll update its timestamp." So I wind up with all the destination files having the same timestamps as the original, but all of the folders having the same just-now-modified date/time.

So I understand what's happening. And I know that I could write my own utility (I have) to copy/move files on NTFS. But utilities are risky---if they aren't NTFS-aware, they could ignore other properties or miss things like NTFS Alternate Data Streams (ADS), etc.

So does anyone know a good, NTFS-aware tree-move utility that will simply move all of a tree and maintain the timestamps? I don't want to risk losing anything. Thanks.

Garret Wilson
  • 18,219
  • 30
  • 144
  • 272
  • On Super User: [How to copy a directory on Windows, preserving timestamps of all directories being copied](http://superuser.com/q/1054206/369446) – DavidRR Dec 23 '16 at 16:22
  • SuperUser is probably a better place to ask this question. – Richard Apr 26 '17 at 23:06

3 Answers3

18

Taking a hint from Helge Klein's answer, I looked more closely into Robocopy. It turns out Robocopy (the latest versions, such as that which comes with Windows 7) can actually duplicate the timestamp of the copied folder structure. There is also a "move" option that deletes the source directory after copying, but in Microsoft's infinite wisdom this is incompatible with the "preserve directory timestamp" option, so you'll have to delete the source tree after doing the copy.

The command-line argument options are daunting. I did some studying, and the basic command to copy preserving directory timestamps using Robocopy is this:

robocopy %1 %2 /e /dcopy:T

...where %1 is the source directory and %2 is the destination directory.

If you want to make sure you copy everything, including NTFS security, owner, and auditing permission, specify that all attributes should be copied and use backup mode, like this:

robocopy %1 %2 /b /e /copyall /dcopy:T

However, using these extra options will require full administrator permissions (not just an administrator account). For example, click Start, right-click on Command Prompt, and then select Run as administrator. Then enter the above command.

P.S. I've verified that Robocopy transfers NTFS streams as well.

Garret Wilson
  • 18,219
  • 30
  • 144
  • 272
  • Wow, good find. I have been using robocopy for a long time but I did not know about /dcopy:T. – Helge Klein Apr 21 '12 at 14:03
  • @GarretWilson, Are you sure that `/b` preserves all the security permissions and attributes? Wouldn't that be `/dopcy:DAT` together with `/copy:DATSOU` `/copyall`? See https://support.microsoft.com/en-us/kb/979808 *"their security configuration information such as an access control list (ACL) is not copied. Instead, these files inherit their ACL from the destination folder"* – Pacerier Apr 25 '15 at 07:16
  • @Pacerier, please proofread your comment. There is no `/dopcy:DAT`, or even `/dcopy:DAT`; there is only `/dcopy:T`. And double-check the command-line help: `/copyall` is equivalent to `/copy:DATSOU`. If you still have a question after proofreading, I'll investigate further. – Garret Wilson Apr 25 '15 at 16:27
  • @GarretWilson, I know that `/copy:DATSOU` == `/copyall`. Also, there is indeed `/dcopy:DAT`. Default is `/DCOPY:DA`, with copyflags `D=Data`, `A=Attributes`, `T=Timestamps`. And again, Are you sure that `/b` preserves all the security permissions and attributes? Wouldn't that be `/dcopy:DAT` together with `/copy:DATSOU` / `/copyall`? See http://support.microsoft.com/en-us/kb/979808: *"their security configuration information such as an access control list (ACL) is not copied. Instead, these files inherit their ACL from the destination folder"*. – Pacerier May 25 '15 at 00:11
  • As of March 2021 on Windows 10, `robocopy %1 %2 /b /e /copyall /dcopy:T` does not preserve folder timestamps. – Christoph Mar 02 '21 at 22:01
3

I was going to recommend robocopy, but when I tried the scenario out, I found (much to my surprise) that it leaves the copied directories at the new dates, as described by you.

Total Commander, on the other hand, copies the timestamps of the directories, too.

Helge Klein
  • 8,829
  • 8
  • 51
  • 71
  • 1
    Helge, your answer is useful so I've gave it a +1. It showed me to Robocopy and, who knows, maybe Total Command is good. But the best approach, I think, may be to use Robocopy with the extra options I found; see my answer. Thanks! – Garret Wilson Apr 21 '12 at 06:01
  • 1
    Just to follow up, I contacted the people who create Total Commander, and they assured me that "Total Commander does copy the 'last modified' timestamps and all the ADS, but the 'last access' and 'created' timestamps are not copied." So Total Commander seems to be an option as well, although I lean towards Robocopy since it's already installed on Windows 7. – Garret Wilson Apr 22 '12 at 15:55
  • +1 for Total Commander! Works like a charm and even supports Win8. ;) – dbernard Feb 09 '13 at 14:25
  • @dbernard, How would we get it to copy the 'last access' and 'created' timestamps? – Pacerier Apr 25 '15 at 07:12
3

SynchronizeIt does that, just as good as Robocopy with a nice GUI and the option to easily see and select which files are going to be copied. http://www.grigsoft.com/wndsync.htm

(Beware though, there are extremely rare cases where this tool somehow corrupts the destination files – it happened to me with files downloaded with download managers, specifically FlashGet and Orbit Downloader, only the first 25kb were correctly copied, the rest was filled with zeros, I don't know the explanation. I've seen Robocopy fail too in equally rare instances – it was confused by similar file names, copied one file instead of the other and thus missed the other. So now I make sure to ALWAYS verify that the copy is perfect using Total Commander or WinMerge.)

Gabriel
  • 31
  • 1