A_LastError will be content-length when available.
Usage: Msgbox % InternetFileGetTime( "http://ahkscript.org/favicon.ico" ) "`nSize = " A_LastError
Code: Select all
InternetFileGetTime( URL, UnixTime=0 ) { ; SKAN | 02-Jan-2014 | goo.gl/zC1Bww
try WebRequest := ComObjCreate( "WinHttp.WinHttpRequest.5.1" )
catch
Return 0, WebRequest := "", ErrorLevel := 1
try WebRequest.Open( "HEAD", URL )
catch
Return 0, WebRequest := "", ErrorLevel := 2
try WebRequest.Send()
catch
Return 0, WebRequest := "", ErrorLevel := 3
try Length := WebRequest.GetResponseHeader( "Content-Length" )
catch {
}
try LastMod := WebRequest.GetResponseHeader( "Last-Modified" )
catch
Return 0, WebRequest := "", DllCall( "SetLastError", UInt,Length ), ErrorLevel := 4
; Convert from RFC2616 string to SYSTEMTIME to FILETIME
VarSetCapacity( SYSTEMTIME, 16, 0 )
If ! DllCall( "winhttp\WinHttpTimeToSystemTime", WStr,LastMod, UInt,&SYSTEMTIME )
Return 0, WebRequest := "", DllCall( "SetLastError", UInt,Length ), ErrorLevel := 5
DllCall( "SystemTimeToFileTime", UInt,&SYSTEMTIME, Int64P,FILETIME )
; Convert from FILETIME to DATETIME
DT := 16010101000000
DT += % ( FILETIME / 10000000 ), S
IfNotEqual, UnixTime, 0, EnvSub, DT, 19700101000000, S
Return DT, WebRequest := "", DllCall( "SetLastError", UInt,Length ), ErrorLevel := 0
}