AutoHotkey Community

It is currently May 26th, 2012, 9:47 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: September 23rd, 2009, 9:37 pm 
Offline

Joined: July 9th, 2009, 9:25 pm
Posts: 120
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)
      }
   }
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 4th, 2009, 8:43 pm 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
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 )
}}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 5th, 2009, 9:44 am 
Offline

Joined: July 9th, 2009, 9:25 pm
Posts: 120
Well, I based it on the built-in one but if you like shorter code, this one is even shorter :wink:
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)
}}


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 6 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group