Sign in to follow this  
Followers 0
snoopie

File time / age modified in milliseconds

1 post in this topic

Greetings,

Since I couldn't find it on the forums, this is what I use to get the time elapsed in milliseconds when a file was last modified:

 

#include <WinAPI.au3>
#include <Date.au3>

$sFile = @ScriptFullPath

$TestTimer = TimerInit()
$iFileAgeMS = _FileAgeInMs($sFile)

If Not @error Then
    ConsoleWrite("Modified " & $iFileAgeMS  & " ms ago. Query took " & TimerDiff($TestTimer) & " ms " & @CRLF)
EndIf

Func _FileAgeInMs($sFile)
    $hFile = _WinAPI_CreateFile($sFile, 2)
    If $hFile = 0 Then
        ConsoleWriteError(_WinAPI_GetLastErrorMessage() & @CRLF)
        SetError(1)
        Return
    Else
        $tFileTime = _Date_Time_GetFileTime($hFile)
        _WinAPI_CloseHandle($hFile)
        $aFileTime = _Date_Time_FileTimeToArray($tFileTime[2])
        $sFileTime = _Date_Time_FileTimeToStr($tFileTime[2], 1)

        $tSystemTime = _Date_Time_GetSystemTime()
        $sSystemTime = _Date_Time_SystemTimeToDateTimeStr($tSystemTime, 1)
        $aSystemTime = _Date_Time_SystemTimeToArray($tSystemTime)

        $iFileAgeS = _DateDiff('s', $sFileTime, $sSystemTime)

        $iFileAgeMS = $iFileAgeS * 1000 + $aSystemTime[6] - $aFileTime[6]

        Return $iFileAgeMS
    EndIf
EndFunc
Quote

Modified 365 ms ago. Query took 0.621854162680013 ms 

 

Share this post


Link to post
Share on other sites



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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0