File 将变量传递到NSIS中for循环的文件函数中
我的问题是: 我无法在for循环中传递变量,它似乎无法识别该变量。它接受带变量的字符串,但不接受变量值。 这是我的密码File 将变量传递到NSIS中for循环的文件函数中,file,for-loop,nsis,File,For Loop,Nsis,我的问题是: 我无法在for循环中传递变量,它似乎无法识别该变量。它接受带变量的字符串,但不接受变量值。 这是我的密码 !define FORMAT "XY 2018|XY 2019" !include "LogicLib.nsh" !include "Explode.nsh" # set the name of the installer Outfile "example.exe" # create a default section. Section ${Explode} $0
!define FORMAT "XY 2018|XY 2019"
!include "LogicLib.nsh"
!include "Explode.nsh"
# set the name of the installer
Outfile "example.exe"
# create a default section.
Section
${Explode} $0 "|" "${FORMAT}"
${For} $1 1 $0
Pop $2
!define PATH_OK "Z:\XY\Doc\List\*$2*"
File "${PATH_OK}"
${Next}
SectionEnd
当我要编译nsis文件时,它返回以下错误:
!define: "PATH_OK"="Z:\XY\Doc\List\*$2*"
File: "Z:\XY\Doc\List\*$2*" -> no files found.
Usage: File [/nonfatal] [/a] ([/r] [/x filespec [...]] filespec [...] |
/oname=outfile one_file_only)
Error in script "C:\Users\Francesco\Desktop\example.nsi" on line 19 aborting creation process
我不明白为什么。。。如果我尝试用消息框更改代码文件“${PATH_OK}”,则路径结果为OK。我哪里做错了?
多谢大家 您在文件名中使用了非法字符(*) 参考:
!define
是一个编译时命令,而变量是在运行时定义和计算的
从:
编译器实用程序命令
这些命令在用途上类似于C预处理器
和功能。它们允许文件包含、条件编译、,
生成期间的可执行头打包和流程执行
过程注意:这些命令都不允许使用变量。
此外,与定义不同,变量不能与
文件命令一起使用。您不能混合和匹配编译时和运行时指令!您还应该了解${define}
和$变量
之间的区别
所有以开头的说明代码>由处理。另一方面,${For}
在最终用户计算机上运行,这对于文件
向安装程序添加文件来说已经太晚了
文件
仅支持基本的DOS通配符(*
和?
):
如果您需要更高级的东西,则必须使用宏或
谢谢你的回复,但我认为问题不在于此。我试图删除通配符,但响应总是一样的:文件:“Z:\T\u CAD\Documentazione\Listini\$2”->找不到任何文件。
这个答案并不能真正解决问题,应该是一个注释吗?
Section
SetOutPath $InstDir
File "c:\mysourcefiles\XY 201?.txt"
SectionEnd
!define FORMAT "XY 2018.txt|XY 2019.txt"
!macro ExplodeAndIncludeFile string sep
!searchparse /noerrors "${string}" "" ExplodeAndIncludeFile_Temp "${sep}"
!ifdef ExplodeAndIncludeFile_Temp
File "${ExplodeAndIncludeFile_Temp}"
!undef ExplodeAndIncludeFile_Temp
!searchparse /noerrors "${string}" "${sep}" ExplodeAndIncludeFile_Temp
!ifdef ExplodeAndIncludeFile_Temp
!insertmacro ${__MACRO__} "${ExplodeAndIncludeFile_Temp}" "${sep}" ; Macro recursion only supported in NSIS 3+
!endif
!endif
!macroend
Section
SetOutPath $InstDir
!insertmacro ExplodeAndIncludeFile "${FORMAT}" "|"
SectionEnd