1

I need to choose the most recently modified file in my installation script. It seems the Pascal scripting language has no GetFileDateTime or similar, so I am resorting to:

function FileDateTime (FileID : string) : double ;

var
   FindRec        : TFindRec;

begin
    Result := 0.00 ;
    if (FindFirst (FileID, FindRec)) then
        begin
        try
            Result := FindRec.LastWriteTime ;  { gives type mismatch, naturally }
        finally
            FindClose (FindRec) ;
        end ;
    end ;
end ;

but I can't find any documentation on the format of LastWriteTime. Ideally I want the datetime returned in a format that will make it relatively easy to display it, as I will need to write the equivalent of Delphi's FormatDateTime as well. Inno Pascal has GetDateTimeString but this only formats the current datetime, not an arbitrary datetime.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
rossmcm
  • 5,493
  • 10
  • 55
  • 118

2 Answers2

2

The documentation on the TFindRec record in InnoSetup is here. It is very sparse, but I am almost confident that it has the exact same format as the corresponding structure in the Windows API.

Indeed, InnoSetup's FindFirst function most likely corresponds to FindFirstFile of the Windows API. Thus, the TFindRec record corresponds to the WIN32_FIND_DATA structure so that a TFileTime record corresponds to a FILETIME structure.

Andreas Rejbrand
  • 105,602
  • 8
  • 282
  • 384
  • so what is the answer, as there is type miss match? how did you match the types? – none Feb 14 '12 at 09:54
  • code could be found at :http://stackoverflow.com/questions/749954/get-a-files-last-updated-time-using-pascal-innosetup/1065605#1065605 – none Feb 14 '12 at 10:22
0
type  
SYSTEMTIME = record 
  Year:         WORD; 
  Month:        WORD; 
  DayOfWeek:    WORD; 
  Day:          WORD; 
  Hour:         WORD; 
  Minute:       WORD; 
  Second:       WORD; 
  Milliseconds: WORD; 
end; 


function FileTimeToSystemTime(
FileTime:        TFileTime; 
var SystemTime:  SYSTEMTIME
): Boolean; 
external 'FileTimeToSystemTime@kernel32.dll stdcall'; 


function GetModifiedFileDate(strFile : String) : Boolean;
var 
   FindRec: TFindRec;  
   SystemInfo: SYSTEMTIME;  
begin 
   if FindFirst(strFile, FindRec) then begin
      FileTimeToSystemTime( FindRec.LastWriteTime, SystemInfo);  
end;  
MsgBox(format('%4.4d-%2.2d-%2.2d', [SystemInfo.Year, SystemInfo.Month, SystemInfo.Day]), mbInformation, MB_OK);
end;
nsdevaraj
  • 317
  • 3
  • 3
  • Nice. But can you modify the `GetModifiedFileDate` so that its signature makes some sense? It's a function returning `Boolean`, but it does not return anything. – Martin Prikryl Dec 07 '16 at 06:41