When I first used Robocopy to migrate files to a new storage drive, I noticed all file and directory timestamps were reset to the copy time. This behavior can cause issues when:
- Tracking file creation history
- Maintaining chronological organization
- Running time-sensitive automation scripts
The solution lies in these critical switches:
robocopy source destination /COPY:DAT /DCOPY:T
Let's break down what each part does:
- /COPY:DAT - Copies Data, Attributes, and Timestamps (D=Data, A=Attributes, T=Timestamps)
- /DCOPY:T - Specifically handles directory timestamps (T=Timestamps)
For a robust copy operation that preserves all metadata:
robocopy C:\source D:\destination /MIR /COPY:DATSOU /DCOPY:T /R:1 /W:1 /ZB /NP /LOG:C:\copy.log
This command includes:
- /MIR - Mirror mode (exact replica)
- /COPY:DATSOU - Extended attributes (Security, Owner, Auditing info)
- /ZB - Uses restartable mode with backup privilege
- /R:1 /W:1 - Minimal retry/wait times
After copying, verify timestamps with PowerShell:
Get-ChildItem D:\destination -Recurse | Select FullName,CreationTime,LastWriteTime | Export-Csv -Path C:\timestamps.csv
For enterprise environments with strict compliance requirements:
robocopy \\server\share\source D:\archive /E /COPYALL /DCOPY:T /TEE /UNILOG+:C:\logs\archive_%date:~-4,4%%date:~-7,2%%date:~-10,2%.log
This adds:
- /COPYALL - All file information (equivalent to /COPY:DATSOU)
- /TEE - Output to console and log
- /UNILOG+ - Unicode log with append mode
When migrating files between drives or servers using Robocopy, many developers encounter an unexpected behavior - all file and directory timestamps get reset to the current copy time. This can break workflows that rely on original creation/modification dates for version tracking, backups, or compliance purposes.
The solution lies in properly combining these essential switches:
robocopy source destination /COPY:DAT /DCOPY:T /R:1 /W:1 /MT:8
/COPY:DAT - Copies Data, Attributes, and Timestamps (D=Data, A=Attributes, T=Timestamps)
/DCOPY:T - Specifically handles directory timestamps (T=Timestamps)
For a complete mirror with timestamp preservation:
robocopy C:\\source D:\\backup /MIR /COPY:DAT /DCOPY:T /ZB /R:3 /W:5 /LOG:backup.log
Network copy with retries and timestamp preservation:
robocopy \\server1\share \\server2\backup /E /COPY:DATS /DCOPY:T /TEE /V /NP /MT:16
- Missing /DCOPY:T when directory dates matter
- Using /COPYALL instead of /COPY:DAT (can copy unnecessary security info)
- Not combining with /MIR properly when mirroring
After copying, verify timestamps with:
dir /T:C /A-D
dir /T:C /AD
Or use PowerShell for more detailed verification:
Get-ChildItem -Recurse | Select-Object Name,CreationTime,LastWriteTime