InnoSetup - 安装前复制文件

时间:2013-05-16 11:31:08

标签: inno-setup

我们如何在安装前复制,移动,重命名用户文件?

我们可以使用[InstallDelete]部分轻松删除文件:

[InstallDelete]
Type: files; Name: "{app}\SomeFile.exe";

我们可以用类似的方式复制,重命名吗?

编辑:

我试图在[Files]部分中进行此操作但在编译期间收到错误,因为源文件不存在:

[Files]
Source: "{app}\SomeFile.exe"; DestDir: "{app}\SomeDir\SomeFile.exe"; 

1 个答案:

答案 0 :(得分:8)

对于复制文件,您可以使用[Files]部分,但我认为没有办法在单独的部分中移动或重命名操作,因此我建议您使用[Code]部分此

以下是移动和重命名操作的示例代码。它们都使用RenameFile函数,因为它在内部是相同的操作:

[Code]
procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssInstall then
  begin
    // move file
    if not RenameFile(ExpandConstant('{app}\SomeDir\SomeFile.exe'), ExpandConstant('{app}\SomeFile.exe')) then
      MsgBox('File moving failed!', mbError, MB_OK);
    // rename file
    if not RenameFile(ExpandConstant('{app}\SomeFile.exe'), ExpandConstant('{app}\RenamedSomeFile.exe')) then
      MsgBox('File moving failed!', mbError, MB_OK);
  end;
end;
相关问题