在Inno Setup Pascal脚本中获取文件的最后修改日期

时间:2011-04-26 23:29:48

标签: datetime scripting inno-setup pascal datestamp

我需要在安装脚本中选择最近修改过的文件。似乎Pascal脚本语言没有GetFileDateTime或类似,所以我诉诸:

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 ;

但我找不到有关LastWriteTime格式的任何文档。理想情况下,我希望以一种格式返回的日期时间使其显示相对容易,因为我还需要编写等效的Delphi FormatDateTime。 Inno Pascal有GetDateTimeString,但这只是格式化当前日期时间,而不是任意日期时间。

2 个答案:

答案 0 :(得分:2)

InnoSetup中TFindRec记录的文档为here。它非常稀疏,但我几乎确信它的格式与Windows API中的相应结构完全相同。

实际上,InnoSetup的FindFirst函数很可能对应于Windows API的FindFirstFile。因此,TFindRec记录对应于WIN32_FIND_DATA结构,因此TFileTime记录对应于FILETIME结构。

答案 1 :(得分: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;