Problem: C:\A\ and C:\B\ contain the same files and folders, but the timestamps in C:\B\ are incorrect.
Solution: Mirror the file and folder timestamp values from C:\A\ to the same files and folders in C:\B\ (without having to recopy the files) via robocopy:
C:\>robocopy C:\A\ C:\B\ /E /DCOPY:T /COPY:T ... Total Copied Skipped Mismatch FAILED Extras Dirs : 3 0 3 0 0 0 Files : 14 14 0 0 0 0 Bytes : 3.339 g 3.339 g 0 0 0 0 Times : 0:00:00 0:00:00 0:00:00 0:00:00 Speed : 239063077333 Bytes/sec. ...
robocopy's log is incorrect; no directories were skipped (all their timestamps were updated), no files were copied (only their timestamp data was), and the hardware wasn't quite up to 239GB/sec.
Options used:
/DCOPY:T what to COPY for directories (T=Timestamps) /COPY:T what to COPY for files (T=Timestamps) /E copy subdirectories, including Empty ones.
Might prove handy for situations like these: How to keep the "date modified" from changing when transferring files to Dropbox?
Another solution is wantfront's PowerShell script*, which "will set the last modified time on all the files/folders (including through sub-dirs) to the last modified time of the one found in the original directory. Worst case scenario, if it doesn't find the file in the original directory it won't do anything.":
$origpath="C:\A\"; $newpath="C:\B\"; get-childitem -Path $newpath -recurse | ForEach-Object { $fullpath=$_.FullName; $fname=$_.Name; If (Test-Path "$origpath\$fname") { "Setting ""$fullpath"" LastWriteTime to the LastWriteTime of ""$origpath\$fname"""; If ( (Get-Item "$fullpath") -Is [System.IO.DirectoryInfo]) { (Get-Item "$fullpath").LastWriteTime = (Get-Item "$origpath\$fname").LastWriteTime; } Else { (Get-ChildItem "$fullpath" ).LastWriteTime = ( Get-ChildItem "$origpath\$fname" ).LastWriteTime; } } }
* Mike J. Brown kindly wrote in with a correction to line 5, from $fname=$_.FullName.TrimStart($newpath);
to $fname=$_.Name;
Experiment with timestamps and other file attributes:
Sources:
/windows | Jan 16, 2019