如何使用Inno Setup重命名文件 [英] How to rename a file using inno setup
问题描述
我想先将现有文件我的旧程序"重命名为我的程序v2",但前提是我的程序v2"尚不存在.
I want to first rename an existing file 'My program old' to 'My program v2' but only if 'My program v2' doesn't already exist.
然后我想将我的程序"重命名为我的程序旧",但前提是我的程序旧"尚不存在.
Then I want to rename 'My program' to 'My program old' but only if 'My program old' doesn't already exist.
然后我想从安装程序安装我的程序",但前提是我的程序"尚不存在.
And then I want to install 'My program' from the installer but only if 'My program' doesn't already exist.
我将非常感谢您提供任何指导!
I would be very grateful for any guidance !
推荐答案
我会尝试这样的事情.在 CurStepChanged
ssInstall阶段中>事件(在安装过程开始之前发生),只需使用 FileExists
函数,如果没有,则只需调用 [Files]
部分中,您可以使用 onlyifdoesntexist
标志用于您的最后一个要求.如果需要,可以遵循此脚本的 commented version
:
I would give a try to something like this. In the ssInstall
stage of the CurStepChanged
event, which occurs just before the installation process starts, just check if the file doesn't exist with the FileExists
function, and if not, then just call the RenameFile
function, which will silently fail if the source file doesn't exist, so you don't need to care if the source file exists. In the [Files]
section you can then use the onlyifdoesntexist
flag for your last requirement. You can follow the commented version
of this script if you want:
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
[Files]
Source: "My program"; DestDir: "{app}"; Flags: onlyifdoesntexist
[Code]
function GetFileName(const AFileName: string): string;
begin
Result := ExpandConstant('{app}\' + AFileName);
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
if (CurStep = ssInstall) then
begin
if not FileExists(GetFileName('My program v2')) then
RenameFile(GetFileName('My program old'), GetFileName('My program v2'));
if not FileExists(GetFileName('My program old')) then
RenameFile(GetFileName('My program'), GetFileName('My program old'));
end;
end;
这篇关于如何使用Inno Setup重命名文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!