Move folder between drives on NTFS and preserve timestamps

Garret Wilson picture Garret Wilson · Apr 20, 2012 · Viewed 33.7k times · Source

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.

Answer

Garret Wilson picture Garret Wilson · Apr 21, 2012

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.