如何在Inno Setup Pascal脚本中设置现有文件的创建时间

埃齐奥

当通过FileCopy(或也RenameFile将文件从目录复制到另一个目录时,原始创建时间更改为当前日期。我想将创建时间设置为原始时间。

我可以通过来获得原始时间值FindFirst,但是如何获取调用时要使用的文件的句柄SetFileTime

[Code]Inno Setup部分中,我有以下代码:

If FileCopy(F1, F2,False) then
  If FindFirst(F1,FindRec) then
    Try
      Fhandle := ??????????? (FindRec.FindHandle don't works)
      SetFileTime(
        Fhandle, FindRec.CreationTime, FindRec.LastAccessTime, FindRec.LastWriteTime)
    finally
      FindClose(FindRec);
    end

编辑:

在回答马丁之后,我对代码进行了如下修改(抱歉,如果还不完美,我是VB.NET程序员,而不是Pascal程序员):

{ C1 and C2 are full Paths }
if Not FileCopy(C1, C2, False) then
   begin
     MsgBox('Data reading error 01. Setup will be aborted.', mbError, MB_OK);
     Result := false;
     exit;
   end;

if FindFirst(C2, FindRec) then 
    try
     begin
      MyTime := FindRec.LastWriteTime //remains the original one
     end;
    finally
      FindClose(FindRec);
    end
 else
   begin
     MsgBox('Data reading error 02. Setup will be aborted.', mbError, MB_OK);
     Result := false;
     exit;
    end;
 end;  

 FileStream := TFileStream.Create(C2, fmOpenReadWrite);
 Try
    if not SetFileTime(FileStream.Handle, MyTime, MyTime, MyTime) Then
       begin
        MsgBox('Data reading error 03. Setup will be aborted.', mbError, MB_OK);
        Result := false;
        exit;
     end;
 Finally
    FileStream.Free;
 end;  
马丁·普里克里(Martin Prikryl)

要获取文件的句柄,可以使用TFileStreamclass

var
  FileStream: TFileStream;
begin
  { ... }
  FileStream := TFileStream.Create(FileName, fmOpenReadWrite);
  try
    SetFileTime(FileStream.Handle, CreationTime, LastAccessTime, LastWriteTime);
  finally
    FileStream .Free;
  end;
end;

尽管正如@Ken所写,在大多数情况下,使用[Files]带有externalflag的节条目会更容易

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在 Inno Setup Pascal Script 中取消引用指针?

如何在Inno Setup中获取MSI文件的文件版本

Inno setup - 如何在设置悬停中更改版本?

如何在Inno Setup iss文件中添加DLL函数?

如何在 Inno Setup iss 文件中调用 GetNativeSystemInfo?

如何在Inno Setup Pascal脚本中检查对象是否为NULL?

Inno Setup-如何在Pascal脚本中本地化字符串?

如何在Inno Setup中翻译MsgBox中包含的文本?

如何在Inno Setup中修改错误消息?

如何在Inno Setup中的安装后强制重启

如何在Inno Setup中解析JSON字符串?

如何在Inno Setup中读取XML的标签属性

如何在Inno Setup中延迟而不冻结

如何从Inno Setup Pascal脚本设置版本号

如何在Inno Setup中设置执行文件的返回码中的退出码?

Inno Setup-如何在设置过程中从文本文件编辑特定行?

Inno Setup Pascal脚本中的多行注释

在Inno Setup Pascal脚本中声明变量

在Inno Setup Pascal脚本中销毁对象

如何在 Pascal 腳本(Inno Setup)中添加睡眠,它將在文件提取之前執行

如何在Inno Setup脚本中从特定目录执行命令

如何在Inno Setup中捕获bat文件的错误消息以删除文件?

如何在Inno Setup中仅根据条件安装文件(外部配置文件)

如何在Inno Setup中基于设置类型跳过自定义页面

如何在Inno Setup中创建两个LicenseFile页面

Inno Setup - 如何在自定义卸载页面中创建新的卸载页面?

如何在Inno Setup中删除非空文件夹

如何在Inno Setup中为每个用户(包括将来的新用户)安装文件?

在Inno Setup中如何在卸载时执行批处理文件?