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

如何为NSIS批量添加的文件设置单独勾选框以实现动态可选?

实现每个文件单独带复选框的NSIS配置

要让每个文件都能被用户单独选择是否安装,你需要把每个文件对应一个独立的NSIS Section——因为NSIS的Section就是安装界面中带复选框的可选项。

修改后的代码示例

; 生成每个目标文件对应的独立Section
!tempfile fileSections
!system 'for /R ".\ParentFolder" %F in ("Same\Path\For\All\*.ext") do @(set "fullpath=%~fF" & set "secname=SEC_!fullpath:\=_!" & set "secname=!secname::=_!" & echo Section "%~nxF" !secname:: & echo SetOutPath $InstDir & echo File "%F" & echo SectionEnd)'
!include "${fileSections}"
!delfile "${fileSections}"

代码说明

  • for /R ".\ParentFolder":递归遍历ParentFolder下所有子目录,找到所有匹配Same\Path\For\All\*.ext的文件
  • 每个文件生成一个独立Section:
    • 显示名称用文件名%~nxF,如果需要让用户看到文件路径,可以改成"%~nxF (%~dpF)"
    • 内部唯一标识secname:把文件完整路径的\和:替换成_,避免Section名称冲突或包含非法字符
  • 每个Section内单独设置SetOutPath $InstDir确保文件安装到指定目录,再用File命令添加单个文件
  • 临时文件fileSections用来存储生成的所有Section代码,引入后自动删除

额外提示

如果目标文件数量极多,大量Section会导致安装界面过于冗长,这时可以考虑按子文件夹分组,用SectionGroup包裹同目录下的文件,既保留分组的复选框,也支持展开选择单个文件:

!tempfile sectionGroups
!system 'for /D %A in (.\ParentFolder\*) do @(echo SectionGroup "%~nxA" GRP_%~nxA & echo SetOutPath $InstDir & echo File /r "%~A\Same\Path\For\All\*.ext" & echo SectionGroupEnd)'
!include "${sectionGroups}"
!delfile "${sectionGroups}"

这种方式下,用户可以先勾选整个文件夹,也可以展开文件夹单独选择里面的文件。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 15:25:18