Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

FileGetTime with milliseconds


  • Please log in to reply
3 replies to this topic
temp01
  • Members
  • 120 posts
  • Last active: May 18 2013 08:27 PM
  • Joined: 09 Jul 2009
FileGetTime( OutputVar, Filename [, WhichTime] ) - See FileGetTime for more info.

The only difference is that this function returns YYYYMMDDHH24MISSMIS instead of YYYYMMDDHH24MISS
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)
		}
	}
}


SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Shortened:

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 )
}}


temp01
  • Members
  • 120 posts
  • Last active: May 18 2013 08:27 PM
  • Joined: 09 Jul 2009
Well, I based it on the built-in one but if you like shorter code, this one is even shorter :wink:
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)
}}


  • Guests
  • Last active:
  • Joined: --
What would be an application for FileGetTime with "milliseconds"?