64

On Linux, we can simply do:

cp -pr directory

How to do that in Windows? Can it be done in Windows Explorer? Any GUI tool suggestions?

It would be the best if I can keep the NTFS permissions and creation/modification/access time. At a minimum, I need to preserve the modification date for the files and the directories. Windows Explorer's copy does not preserve the modification date for directories.

7
  • possible duplicate of How to copy files while not modifying the file creation times at all?
    – user1931
    May 27, 2010 at 23:20
  • 1
    I don't think it's a duplicate. File creation time is only one of the file attributes.
    – netvope
    May 28, 2010 at 1:01
  • The answers in that question provide software which will preserve all timestamps, mtime, ctime, and atime.
    – user1931
    May 28, 2010 at 1:11
  • This may be of interest: support.microsoft.com/kb/310316 . Unfortunately some of these registry keys no longer work in Vista and upwards.
    – Amro
    Jun 7, 2013 at 12:21
  • 1
    robocopy c:\folderA c:\folderB /mir /it is all you need. Note that this will completely delete c:\folderB and create a new c:\folderB that mirrors c:\folderA.
    – Pacerier
    May 4, 2016 at 3:54

17 Answers 17

7

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.

0
39
+300

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.

9
  • 1
    Good answer. Should be the chosen one, as the first one is kinda outdated. Used robocopy since Windows 7 to trim empty directoeies from client's backups, however, I THINK it was available since Windows XP
    – DGoiko
    Mar 28, 2019 at 17:33
  • @DGoiko I think you're right. I used it extensively with Windows 7 for sure. Unfortunately, buying special Windows 7 Pro laptops is no longer an option. So I now have Win 10. I don't think I ever looked when I had XP, but it's been around a long time. Just Not so well known. Mar 28, 2019 at 20:37
  • Robocopy GUI is excellent. May 10, 2019 at 16:13
  • However, I understand that the destination files can be mirrored with the source file's last access, but does robocopy cause the Last Accessed timestamp of the source files to be effected?_ I need to be able to copy a bunch of data and reliably (without gotcha) and have every time attribute including last access time of the source tree left alone entirely. Apr 24, 2020 at 17:19
  • In my case, it also turned out to be important to use the /XJ and /SL switches, because without them Robocopy recursed through links/junctions with no cycle detection, which led to a problem described in this answer. Documentation for the flags: docs.microsoft.com/en-us/windows-server/administration/… Dec 25, 2020 at 1:08
30

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

5
  • Cool idea. But does this copy over "the other stuff" like file properties and etc etc?
    – Pacerier
    May 4, 2016 at 2:36
  • 3
    This does not always work. With 7-zip for example, using 7zip compression doesn't preserve one of the file times (I forget which). It does not preserve any directory times (as I recall), With ZIP, you can preserve both created and modified times, but 7zip only keeps some of the times depending on how you unzip: whether you drag and drop or extract from the program menu. Test well, young grasshopper.
    – Jon
    Oct 12, 2016 at 3:30
  • 3
    Thank you very much, this worked nice for me. I used 7zip, with ZIP format (creation date is not preserved in 7Z format).
    – AFract
    Jan 15, 2017 at 9:19
  • 1
    Could you add the specific command you would use to do this? An example of the specific command to use the compression method you suggested? This would make it more of a complete Answer", as opposed to more of a suggestion or comment. It would also save countless people from having to perform a search to figure out how to accomplish your suggestion. Also, as a bonus, a link to docs or an article with more info about this method would be awesome. Providing all the info saves everyone else from reinventing the (search) wheel, and can dramatically increase upvotes. We thank you! Mar 28, 2019 at 18:07
  • This seems promising, but sadly cannot zip from a so-called "media device" connection, ie. my phone.
    – Ed Randall
    Mar 10, 2021 at 8:48
24

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.

6
  • In Windows robocopy is the recommended way to do this since it not only copies file/folder attributes but also allows for proper file integrity and error handling during the entire copy process.
    – megamorf
    Jan 1, 2014 at 11:15
  • @megamorf: In what way does robocopy do anything special? It doesn't do any checksumming or hashing of the data, it relies on the OS to report errors just like almost any other program.
    – afrazier
    Jan 1, 2014 at 17:44
  • I agree that as of now robocopy has no pre-post checksum comparison feature. But in general, robocopy will retransmit the entire file when an error occurs. If you want it to resume writing the rest of a file to the destination after an error occurred without transmitting the entire file again you specify the /Z switch.
    – megamorf
    Jan 1, 2014 at 18:25
  • @afrazier, Why not simply use /mir?
    – Pacerier
    May 4, 2016 at 3:54
  • 2
    @Pacerier, because the question isn't about mirroring a tree, it's about copying files and folders and preserving as much metadata as possible. Not only does /mir remove data from the destination folder, you still needed the /dcopy:t to preserve directory mtimes and /copyall to preserve more than just the file timestamps.
    – afrazier
    May 4, 2016 at 13:29
4

RoboCopy should be able to do it with the COPYALL switch. You can grab the GUI version from Microsoft Technet.

4

Synchronize It! 3.5 keeps all timestamps (files and folders, modification and creation). It's the only software I know on Windows XP which does that flawlessly, beside Robocopy, and I've tried many. Beware, though, it can produce corrupted files with source files downloaded using software like FlashGet or Orbit Downloader (the resulting files have the same size but only 25kB is actually copied - the rest is filled with zeros). I asked the creator of the software if he could figure out why, but he had no clue; I guess it has to do with such software downloading files in small packets (intended to optimize speed) and my data partition being hugely fragmented.

Robocopy XP026 is indeed included in Windows Vista, but works on Windows XP. Search "Robocopy XP026", or I can send the file here as it's not very easy to find. Or you can install Robocopy GUI and then search for the robocopy.exe file in the System32 folder, so as to use it from the command line. The file I have is 208kB and the version number is 5.1.2600.26.

There seems to be a bug with the "backup mode", though:

http://msmvps.com/blogs/martinzugec/archive/2008/03/03/ugly-bug-in-robocopy-ignoring-security-on-file-level.aspx

Robocopy version XP027 apparently no longer has this bug but it doesn't work on Windows XP.

2
  • File download utilities (like Bittorrent) allocate the full size of the file on disk (filled with 0), and download sections from multiple sources, storing them in the right place in the file. The files when started will have many 0000. Either the file was never completely downloaded or Synchronize It! saw too many 0000 and gave up the copy.
    – Chloe
    Mar 1, 2013 at 19:18
  • Thanks! I used Synchronize It! It's so fast too! SyncToy and Unison were messing up the file modification times. Unison was corrupting Cygwin symlinks. SyncToy was even copying 'My Music' which turned out to be in a junction on the destination, but when I refreshed, it kept wanting to copy over again, even though everything was the same!
    – Chloe
    Mar 2, 2013 at 7:32
2

FastCopy can do this and it is free.

2

I spent days trying to copy about 600 GB of files from one external drive to another external drive using freeware. I tried Robocopy and a number of its GUIs. Also Roadkill's Unstoppable Copier, and more.

Each failed at one point or another, or completed but it turned out skipped/failed to copy thousands of files.

I finally broke down and paid $50 for GS RichCopy 360 after reading about it while looking for a solution. I had some problems and their support, which is apparently provided by their developers, was very helpful, during multiple phone calls, some late at night (they explained they sell to IT professionals that typically do maintenance at night).

GS RichCopy 360 not only worked to copy the folders and files, but also by default copies folders and files with the creation date and modification date of the source files, as the OP is looking for. That makes it possible to search the copied files based on creation date with software like Agent Ransack.

If GS RichCopy 360 stalls out (my source external drive was intermittently disconnecting and not being recognized by Windows) if you have it set to copy only files that are not already on the destination drive, you can restart the copy job and it very quickly blows through the files that have already been copied and picks up where it left off.

It was not phased by some very long file names, well over 260 characters, or by some large files (some over 4 GB).

I don't have money to spare but after wasting days it was well worth the money, and now I have it for other large copy jobs in the future. It has an easy to use GUI, with logical options, and most important, it works.

Edit: I also tried the archive file solution suggested by Silkworm, with 7zip and another archive program, but that also stalled out/failed. That should have worked as from what I have read 7zip can archive way more than the under several hundred GB archives I was trying to create, but for some reason did not (or perhaps it was working and I did not know it and did not wait long enough).

With GS RichCopy 360 progress was easy to see graphically for each thread individually, and the total (you can set the number of threads based upon what your processor can handle, up to some huge number, their support recommended my Intel i5 was good for 4 threads).

2
  • Sounds like your problem was the existence of paths with more than 260 characters. While it is possible in some cases for files to have longer paths, it is normally the result of a process that shouldn't have allowed that. In those cases, many programs that check for that fail to copy because they are protecting your file system or they are relying on the OS to allow or disallow it. Creating longer paths, even when things seem to be successful, can actually corrupt your file system and cause you bigger issues in the future. Dec 31, 2020 at 0:38
  • This solution smells of spam! I am constantly seeing plugs for GS RichCopy all over on the internet following a post about Robocopy. The pattern is identical to that seen in this solution: "I tried the suggested solutions but it did not work, try GS RichCopy, it works". Caveat Emptor! (Buyers Beware!). Readers, exercise caution! It's a shame because if I had witnessed genuine reviews, I would likely purchased it myself. But the integrity of the brand is not there and it now has a negative image due to numerous bogus looking reviews of the product.
    – IqbalHamid
    Apr 3, 2021 at 15:59
1
xcopy *.* C:\temp\Pics /c /d /e /h /i /k /q /r /s /x /y

I am not sure which switch maintains the file date but this works. Then I zip the C:\temp\Pics directory which also maintains file dates as mentioned earlier.

3
  • 1
    How does zipping the copy fit into this discussion? Aug 19, 2013 at 20:01
  • It fits by also maintaining timestamps for the [zipped] files, something that seems to occupy the person who asked the question. You're welcome, Scott. This happens to make for a useful answer, if not the correct one. Aug 20, 2015 at 16:31
  • This does preserve file date/time, but does not do so for folder.
    – barneco
    Sep 8, 2017 at 17:44
1

xcopy works fine for this. Just specify the /k flag to copy attributes.

Syntax
xcopy Source [Destination][Optional parameters]

The xcopy command can copy one or more files or directory trees from one location to another. The xcopy command is included in all versions of Windows from Windows 95 to Windows 8.

3
  • 1
    I just tried the /K parameter and it did not preserve the creation dates.
    – CodeManX
    Jan 4, 2016 at 18:30
  • It seems to me as it works sometimes and sometimes doesnt - windows at its best ;)
    – SebastianH
    Jan 5, 2017 at 9:14
  • This is the solution that worked for me on the Modified Date. I was copying files to a SharePoint folder (via mapped drive) and the dates were being set to today's date before I included the /k switch with xcopy. It appears the the correct Created Date is only copied when the file is new. When overwriting an existing file the Created Date is preserved from the first copy.
    – Ben
    Dec 22, 2020 at 17:14
1

The simplest way for me, so far, is the "send to" method. It does not need any external applications. In my experience, it retains all of the original file attributes.

The method I used before, was the compression/zip folder method. Though this is surely to take longer since the files are not only copied, but processed and compressed, both when compressing and decompressing.

%appdata%\Microsoft\Windows\SendTo
or. C:\Users\_______\AppData\Roaming\Microsoft\Windows\SendTo

Add a shortcut to the folder where you want them copied, and the item will appear in your sendto menu when you right-click a file you want to copy.

1
  • 2
    Thanks for sharing the trick of using "Right click > Send to". It works, except for the creation date. Previously, I was using the native xcopy command: xcopy Source Destination /kes. (The kflag allows to preserve the modification timestamp, but the creation date is not preserved). The compression method to zip (or rar) is a good method, but often takes too long.
    – OuzoPower
    Jun 21, 2018 at 4:37
1

Teracopy preserves dates too and is GUI-based

1
  • this is the best answer. Oct 7, 2022 at 3:07
0

Simple way to move folders and preserving Creation Date & Time use these utilities

http://lantechsoft.com/data-copy.html

Another one where it can preserve dates while copying files.

http://technocomsolutions.com/data-copy-tool.html

0

I achieve this with

rsync -avu --modify-window=3602 source_directory/ target_directory/

(this is really used as a syncing tool from one directory to another mirror and the timewindow option is to prevent issues when windows systems move clocks 1 hour for daylight savings etc. compared to linux systems)

in either cygwin environment inside windows or a linux virtual machine inside windows with windows drives mounted (e.g. with virtualbox)

NB cygwin and virtualbox are both free and enable you to have to a lesser or greater extent linux functionality on windows - they both require a bit of setting up - particularly virtualbox, but have many benenfits....

My own issue was that files have the correct time but directories did not. rsync has sorted out the dates on the directories as well as the dates on the files.

0

This command copies the same time stamp for files. Note it doesn't do exactly the same time stamping for the folders themselves. Also note that I placed quotes around both source (Temp1) and destination (Temp2). This is done in case there are spaces in the paths. I don't have any spaces but I thought I should include it for worst case scenarios.

robocopy /E /copy:DAT "C:\Temp1" "c:\Temp2"

To keep timestamps the same for folders as well:

robocopy /E /copy:DAT /dcopy:DAT "C:\Temp1" "c:\Temp2"

0

If you've already copied it and don't want to again, you can run this Python script to update the creation/modified/access times to mirror the original source.

Usage:

python mirror_file_times.py /src/dir /dest/dir

Requirements (pathlib):

pip install pypiwin32 tqdm

It should work on Linux, but I haven't tested it.

-1

It's simple to move folders and directories and still preserving Creation Date. Just hold Shift and drag the folder to the new location (move command). Date Modified will be the present date but Date Created will retain the original date.

2
  • 6
    DO NOT DO THIS! This deletes the files from the original folder. Just lost irrecoverable data from my phone by trying to do this (no CTRL+Z does not work).
    – BadAtPHP
    Mar 13, 2017 at 12:01
  • It's the other way around: Create Date will be the present, but Modified Date will be the original. And for @BadAtPHP: To be fair, the user clearly say it would MOVE the files, not COPY them. Dec 31, 2020 at 0:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .