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

发布于 2024-11-03 15:49:40 字数 689 浏览 2 评论 0原文

我需要在安装脚本中选择最近修改的文件。看来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 但这仅格式化当前日期时间,而不是任意日期时间。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

り繁华旳梦境 2024-11-10 15:49:41

有关 InnoSetup 中 TFindRec 记录的文档位于此处。它非常稀疏,但我几乎确信它具有与 Windows API 中相应结构完全相同的格式。

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

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.

十雾 2024-11-10 15:49:41
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 '[email protected] 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;
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 '[email protected] 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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文