如何在安装前复制,移动,重命名用户文件?
我们可以使用[InstallDelete]部分轻松删除文件:
[InstallDelete]
Type: files; Name: "{app}\SomeFile.exe";
Run Code Online (Sandbox Code Playgroud)
我们可以用类似的方式复制,重命名吗?
编辑:
我尝试在[Files]部分中进行此操作但在编译期间收到错误,因为源文件不存在:
[Files]
Source: "{app}\SomeFile.exe"; DestDir: "{app}\SomeDir\SomeFile.exe";
Run Code Online (Sandbox Code Playgroud)
对于复制文件,您可以使用该[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;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5502 次 |
| 最近记录: |