[已解决]如何获取文件修改时间,要毫秒级
本帖最后由 805333 于 2011-10-12 22:12 编辑如何获取文件修改时间,要毫秒级,FileGetTime 只能获取到秒 有什么特别的用途吗?有必要取到毫秒级? au3有这个精度吗? windows的文件修改时间就没到毫秒过,如果是系统关键文件,用性能计数器可能还能取到(不太确定) 楼主 毫秒级 无意义啊。。 hehe,这个有点难,windows不关心毫秒的东西 这个要求也太高了点吧!估计很难做到! 以前曾在网上看到一段话:当AU3运用得已经非常熟练,以为是编程高手的时候,却不知道API函数TerminateProcess 是做什么用的。 现在这情况真相似啊。
Func _FileGetTime($sFilePath, $iTime = 1, $fText = 1)
Local Const $tagFILETIME = "dword LowDateTime;dword HighDateTime"
Local Const $tagSYSTEMTIME = "word Year;word Month;word DayofWeek;word Day;word Hour;word Minute;word Second;word Milliseconds"
Local $hFile = DllCall("Kernel32.dll", "handle", "CreateFileW", "wstr", $sFilePath, "dword", 0x80000000, "dword", 3, "dword", 0, "dword", 3, "dword", 0, "handle", 0)
$hFile = $hFile
If ($hFile < 1) Then Return SetError(1, 0, "")
Local $tCreationTime, $tLastAccessTime, $tLastWriteTime
Switch $iTime
Case 1
$tCreationTime = DllStructCreate($tagFILETIME)
Case 2
$tLastAccessTime = DllStructCreate($tagFILETIME)
Case Else
$iTime = 3
$tLastWriteTime = DllStructCreate($tagFILETIME)
EndSwitch
Local $iResult
$iResult = DllCall("Kernel32.dll", "bool", "GetFileTime", _
"handle", $hFile, _
"ptr", DllStructGetPtr($tCreationTime), _
"ptr", DllStructGetPtr($tLastAccessTime), _
"ptr", DllStructGetPtr($tLastWriteTime))
DllCall("Kernel32.dll", "bool", "CloseHandle", "handle", $hFile)
If ($iResult = 0) Then Return SetError(1, 0, "")
Local $tFileTime = DllStructCreate($tagFILETIME)
Local $pFileTime = DllStructGetPtr($tFileTime)
Local $tSysTime = DllStructCreate($tagSYSTEMTIME)
Local $pSysTime = DllStructGetPtr($tSysTime)
DllCall("Kernel32.dll", "bool", "FileTimeToLocalFileTime", "ptr", $iResult[$iTime + 1], "ptr", $pFileTime)
DllCall("Kernel32.dll", "bool", "FileTimeToSystemTime", "ptr", $pFileTime, "ptr", $pSysTime)
Local $aResult
$aResult = DllStructGetData($tSysTime, "Year")
$aResult = DllStructGetData($tSysTime, "Month")
$aResult = DllStructGetData($tSysTime, "Day")
$aResult = DllStructGetData($tSysTime, "Hour")
$aResult = DllStructGetData($tSysTime, "Minute")
$aResult = DllStructGetData($tSysTime, "Second")
$aResult = DllStructGetData($tSysTime, "Milliseconds")
If $fText Then
Return StringFormat("%04d/%02d/%02d %02d:%02d:%02d.%03d", $aResult, $aResult, $aResult, $aResult, $aResult, $aResult, $aResult)
Else
Return $aResult
EndIf
EndFunc ;==>_FileGetTime 向P版学习啊。。 谢谢老大,哈哈,老大出面就是不一样啊 要这么精确吗? 楼主确实强大~!~试了 确实厉害!!
对windows api不熟悉的路过~!~ 又学到点东西,不过暂时还无需这么精确! {:face (288):}毫秒级误差大,没必要吧 谢谢分享。
页:
[1]