Move folder between drives on NTFS and preserve timestamps

34,963

Solution 1

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.

Solution 2

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.

Solution 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.)

Share:
34,963

Related videos on Youtube

Garret Wilson
Author by

Garret Wilson

Updated on July 09, 2022

Comments

  • Garret Wilson
    Garret Wilson almost 2 years

    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
    Garret Wilson almost 12 years
    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!
  • Helge Klein
    Helge Klein almost 12 years
    Wow, good find. I have been using robocopy for a long time but I did not know about /dcopy:T.
  • Garret Wilson
    Garret Wilson almost 12 years
    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.
  • dbernard
    dbernard about 11 years
    +1 for Total Commander! Works like a charm and even supports Win8. ;)
  • Pacerier
    Pacerier almost 9 years
    @dbernard, How would we get it to copy the 'last access' and 'created' timestamps?
  • Pacerier
    Pacerier almost 9 years
    @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 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"
  • Garret Wilson
    Garret Wilson almost 9 years
    @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.
  • Pacerier
    Pacerier almost 9 years
    @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 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".
  • Christoph
    Christoph about 3 years
    As of March 2021 on Windows 10, robocopy %1 %2 /b /e /copyall /dcopy:T does not preserve folder timestamps.
  • Smeterlink
    Smeterlink almost 3 years
    Perfect just what I needed. Total Commander doesn't do it.

Related