VAN0 Posted September 28, 2022 Share Posted September 28, 2022 FileCopy() preserves only lastmodifed timestamp. creationdate and lastaccessed timestamps are set at the moment of copy the file. NTFS timestamp accuracy is in microseconds, but AutoIt can get it in milliseconds and set in seconds, making FileGetTime() and FileSetTime() not accurate enough. How can I create an identical copy of a file with identical timestamps? Thanks. Test code: #include <WinAPIFiles.au3> Local $sNow = @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & @MSEC $sFile = @TempDir & "\test" & $sNow & ".txt" $sFile2 = $sFile & ".copy.txt" FileWrite($sFile, $sNow) Sleep(2111) FileCopy($sFile, $sFile2) FileSetTime($sFile2, FileGetTime($sFile, $FT_CREATED, 3), $FT_CREATED) ConsoleWrite(@CRLF) ConsoleWrite("orig FileGetTime: " & FileGetTime($sFile, $FT_CREATED, 3) & @CRLF) ConsoleWrite("orig wmic : " & getTime($sFile) & @CRLF) ConsoleWrite("copy FileGetTime: " & FileGetTime($sFile2, $FT_CREATED, 3) & @CRLF) ConsoleWrite("copy wmic : " & getTime($sFile2) & @CRLF) FileDelete($sFile) FileDelete($sFile2) Func getTime($sFile) Local $iPid = Run('wmic datafile where name="' & StringReplace($sFile, "\", "\\") & '" get creationdate', "", @SW_HIDE, 2) Local $sOut ; Do $sOut &= StdoutRead($iPid) Until @error Return StringRegExpReplace($sOut, "[^\d.-]", "") EndFunc ;==>getTime Link to comment Share on other sites More sharing options...
argumentum Posted September 28, 2022 Share Posted September 28, 2022 #include <Date.au3> _Date_Time_SetFileTime ( $hFile, $tCreateTime, $tLastAccess, $tLastWrite ) VAN0 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now