You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Inno Setup中检测文件夹是否存在并重命名新文件夹

Inno Setup 动态命名目标文件夹实现方案

实现步骤

  1. 编写路径检测逻辑
    在脚本的[Code]段添加自定义函数,利用DirExists检测目标位置的example文件夹是否存在,并返回最终的目标路径:
function GetTargetFolder(Param: String): String;
var
  BasePath: String;
begin
  // BasePath为你指定的根目标位置,这里用向导默认的安装目录{app}
  BasePath := ExpandConstant('{app}');
  
  // 检测example文件夹是否存在
  if DirExists(BasePath + '\example') then
  begin
    Result := BasePath + '\example_2';
  end
  else
  begin
    Result := BasePath + '\example';
  end;
end;
  1. 修改Files段的目标路径
    将原[Files]段中固定的DestDir替换为动态获取的路径,确保文件解压到正确的文件夹:
[Files]
; 替换"你的源文件夹"为实际要打包的文件夹路径
Source: "你的源文件夹\*"; DestDir: "{code:GetTargetFolder}"; Flags: recursesubdirs createallsubdirs

DirExists函数说明

DirExists是Inno Setup内置的目录检测函数,用法直接:

  • 接收参数:完整的文件夹路径字符串
  • 返回值:布尔值,目录存在返回True,不存在返回False
  • 示例:DirExists('C:\Program Files\example')会检测该路径下的文件夹是否存在

内容的提问来源于stack exchange,提问作者Erufen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 15:52:41