 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
temp01
Joined: 09 Jul 2009 Posts: 120
|
Posted: Wed Sep 23, 2009 8:37 pm Post subject: FileGetTime with milliseconds |
|
|
FileGetTime( OutputVar, Filename [, WhichTime] ) - See FileGetTime for more info.
The only difference is that this function returns YYYYMMDDHH24MISSMIS instead of YYYYMMDDHH24MISS
| Code: | FileGetTime( time1, "C:\Windows", "M" )
FileGetTime, time2, C:\Windows , M
Msgbox, % time1 . "`n" . time2
; based on the built-in FileGetTime function
FileGetTime(ByRef OutputVar, Filename, WhichTime="M"){
OutputVar := ""
VarSetCapacity( WIN32_FIND_DATA, 318, 0 )
file := DllCall("FindFirstFile", "str", Filename, "UInt", &WIN32_FIND_DATA)
IfEqual, file, -1, return !(ErrorLevel:=1) ; INVALID_HANDLE_VALUE
DllCall("FindClose", "UInt", file)
If whichtime = C
pFILETIME := &WIN32_FIND_DATA + 4
Else if whichtime = A
pFILETIME := &WIN32_FIND_DATA + 12
Else If whichtime = M
pFILETIME := &WIN32_FIND_DATA + 20
Else
return !(ErrorLevel:=1)
VarSetCapacity(local_FILETIME, 8, 0)
If DllCall("FileTimeToLocalFileTime", "UInt", pFILETIME, "UInt", &local_FILETIME){
VarSetCapacity(SYSTEMTIME, 16, 0)
If DllCall("FileTimeToSystemTime", "UInt", &local_FILETIME, "UInt", &SYSTEMTIME){
VarSetCapacity(local_filetime_str, 128, 0)
If DllCall("msvcrt.dll\sprintf", "Str", local_filetime_str, "Str", "%04d%02d%02d" "%02d%02d%02d%03d"
, "UInt", NumGet(SYSTEMTIME,00,"UShort"), "UInt", NumGet(SYSTEMTIME,02,"UShort"), "UInt", NumGet(SYSTEMTIME,06,"UShort") ; Y M D
, "UInt", NumGet(SYSTEMTIME,08,"UShort"), "UInt", NumGet(SYSTEMTIME,10,"UShort") ; H M
, "UInt", NumGet(SYSTEMTIME,12,"UShort"), "UInt", NumGet(SYSTEMTIME,14,"UShort"), "CDecl")>=0 ; S MS
{
OutputVar := local_filetime_str
return !(ErrorLevel:=0)
}Else
return !(ErrorLevel:=1)
}
}
}
|
|
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 8688
|
Posted: Sun Oct 04, 2009 7:43 pm Post subject: |
|
|
Shortened:
| Code: | FileGetTime( File, Mode="M" ) { ; Topic: www.autohotkey.com/forum/viewtopic.php?t=49194
If ( VarSetCapacity($,342,0) && ( H:=DllCall( "FindFirstFile", Str,File, UInt,&$ ) ) ) {
DllCall( "FindClose", UInt,H ), VC:=&$+4, VA:=&$+12, VM:=&$+20, FT:=V%Mode%
LFT:=&$+318 , DllCall( "FileTimeToLocalFileTime", UInt,FT, UInt,LFT )
ST:=LFT+8 , DllCall( "FileTimeToSystemTime", UInt,LFT, UInt,ST )
Loop 7
T .= StrLen( N:=NumGet(ST+0,(A_Index-1)*2,"UShort") ) < 2 ? "0" N : N
Return SubStr(T,1,6) . SubStr(T,9,8) . SubStr( "00" NumGet( ST+0,14,"UShort" ), -2 )
}} |
|
|
| Back to top |
|
 |
temp01
Joined: 09 Jul 2009 Posts: 120
|
Posted: Mon Oct 05, 2009 8:44 am Post subject: |
|
|
Well, I based it on the built-in one but if you like shorter code, this one is even shorter
| Code: | FileGetTime(fn, time="M", tC=4, tA=12, tM=20){
If VarSetCapacity(s,342,0) && DllCall("FindClose", UInt,DllCall("FindFirstFile", str,fn, UInt,&s))
&& DllCall("FileTimeToLocalFileTime", UInt, &s+t%time%, UInt, _:=&s+318)
&& DllCall("FileTimeToSystemTime", UInt, _+0, UInt, _+=8){
Loop 7
out .= (n:=NumGet(_+0, A_Index*2-2, "UShort")) < 10 ? 0 n : n
Return SubStr(out, 1, 6) SubStr(out, 9) SubStr("00" NumGet(_+0, 14, "UShort"), -2)
}} |
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|