How to preserve file attributes when one copies files in Windows?

There's no simple way to do this in Windows.  There are several programs that claim to be able to preserve the creation dates of files.
Here are a few programs that might do the trick http://forum.soft32.com/windows/preserve-creation-date-Copy-ftopict361820.html  (Broken link; not in the Wayback Machine).

Using just Windows Explorer it's not possible. If you look at the documentation for CopyFile, CopyFile function (winbase.h), you will see that it avoids the subject.  But CopyFile function (Windows Developer Preview) (a 2012 archive of the same URL) says:

File times semantics

This article should document semantics with respect to file creation/modification/access times.

Creation time: if the target file already exists, its' creation time is preserved, otherwise it is set to the current system time.
Last Modification time: always copied from modification time of the source file.
Last Access time: always set to the current system time.


... or you can just make a zip archive (with compression method set to just "Store"), and then unpack the files where you wanted to copy them. The date/time attributes are the same as the original files.


RoboCopy can preserve the mtime for directories with the /DCOPY:T switch, but this only works in Vista and newer. It can also preserve ACLs. Alternatively, FastCopy can be configured to preserve directory mtimes, ACLs, and ADSes.


Robocopy command line tool (comes with most versions of windows)
On my windows 10 machine it is located at C:\Windows\System32

From Wikipedia, it can be used with the following set of options to preserve file and directory timestamps, as well as other attributes:

Robocopy C:\some_directory D:\some_directory /DCOPY:T /COPYALL /E /R:0

  • /DCOPY:T preserve original Directories' Timestamps (requires version XP026 or later)
  • /E: Copy directories recursively, including Empty Directories
  • /R:0: do not retry locked files (the number of retries on failed copies default value is 1 million),

  • /COPYALL: Copy all file information,
    (equivalent to /COPY:DATSOU, where

    • D=Data,
    • A=Attributes,
    • T=File Timestamps,
    • S=Security=NTFS ACLs,
    • O=Owner info,
    • U=Auditing info),

If you only want to preserve date and directory timestamps, but do not want empty subdirectories copied over and do not want other attributes preserved then you may use:
Robocopy C:\some_directory D:\some_directory /DCOPY:T /COPY:T /S

where /S copies non-empty subdirectories

To see the full syntax, type robocopy /? at a command prompt, or take a look at these blog posts: https://ss64.com/nt/robocopy.html and https://techjourney.net/robocopy-syntax-command-line-switches-and-examples/

An example of a command I recently ran:
Robocopy D:\ C:\D_backup /DCOPY:T /COPYALL /E /R:0 /ZB /ETA /TEE /V /FP /XD D:\$RECYCLE.BIN /XD "D:\System Volume Information" /LOG:C:\D_backup_robocopy.LOG /MIR

Notice how excluding 2 subdirectories requires the /XD flag to be used twice. Also, the second directory exclusion uses quotes because there are spaces in the directory name.

Finally, you can add the /L flag to test the command before doing it for real. In this way you can verify it won't copy (or remove) any directories/files that you do not want, and that there are no errors in your command.

Edit: gotcha when copying from a Root Directory (aka drive) to a Folder (non-root directory)

After running the example command above, the directory was not visible! (Even though show hidden files and show system files were checked in Windows 10!) The following command as per https://serverfault.com/a/455029/399723 fixed this:

attrib -h -s C:\D_backup

Alternatively, adding the /A-:SH "unsets the Hidden Attribute from System files", thus may prevent the directory from becoming hidden in the first place, as per https://serverfault.com/a/565804/399723. See also https://ss64.com/nt/robocopy.html.
This descussion sheds more light on this option as a solution.

Robocopy D:\ C:\D_backup /A-:SH /DCOPY:T /COPYALL /E /R:0 /ZB /ETA /TEE /V /FP /XD D:\$RECYCLE.BIN /XD "D:\System Volume Information" /LOG:C:\D_backup_robocopy.LOG /MIR

Other Software:

Alternatively, you can download a GUI version of robocopy if you don't want to use the command line.

Another windows utility is XCopy, though it is included in windows 10, it is being deprecated. See the link for gotchas.

The Wikipedia page for RoboCopy (linked at top of this post) lists other software that can be used.