InnoSetup-安装前复制文件 [英] InnoSetup - copy files before install
问题描述
在安装之前,我们如何复制,移动,重命名用户文件?
How can we copy, move, rename user files before installation?
我们可以使用[InstallDelete]部分轻松删除文件:
We can easily delete files using the [InstallDelete] section:
[InstallDelete]
Type: files; Name: "{app}\SomeFile.exe";
我们可以用类似的方式复制,重命名吗?
Can we do copy, rename in a similar way?
我试图在[Files]部分中做到这一点,但由于源文件不存在,因此在编译过程中收到错误消息:
I tried to make this in [Files] section but I receive an error during compilation because source file does not exist:
[Files]
Source: "{app}\SomeFile.exe"; DestDir: "{app}\SomeDir\SomeFile.exe";
推荐答案
要复制文件,您可以使用[Files]
部分,但是我认为没有办法在单独的部分中进行移动或重命名操作,因此我建议您使用[Code]
部分.
For copying files you can use the [Files]
section, but I don't think there's a way for move or rename operations in a separate section, so I would suggest you to use [Code]
section for this.
这是移动和重命名操作的示例代码.它们都使用 RenameFile
函数,因为它在内部是相同的操作:
Here is a sample code for move and rename operations. They both use the RenameFile
function as it is internally the same operation:
[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;
这篇关于InnoSetup-安装前复制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!