[英]NSIS - Install a file to a pre-existing, uncertain subfolder?
我正在尝试将文件安装到结构如下的现有文件夹中:
$APPDATA/somefolder/(uncertainFolder)
“ uncertainFolder”将为“ 1.0”或“ 2.0”。
尽管文件夹名称不同,相同的文件也将安装到“ uncertainFolder”中。 我该如何实现?
先感谢您。
使用File
指令安装的File
被提取到SetOutPath
设置的目录中。 一旦知道所需的文件夹,就可以在运行时更改此路径。
如果在编译时已知可能的文件夹名称,则可以使用if / or / if / else:
!include LogicLib.nsh
${If} ${FileExists} "$InstDir\SomeFolder\2.0\*.*"
SetOutPath "$InstDir\SomeFolder\2.0"
${Else}
SetOutPath "$InstDir\SomeFolder\1.0"
${EndIf}
您还可以在运行时枚举文件和文件夹:
FindFirst $0 $1 "$InstDir\SomeFolder\*.*"
loop:
StrCmp $1 "" end ; No more files?
StrCmp $1 "." next ; DOS special name
StrCmp $1 ".." next ; DOS special name
IfFileExists "$InstDir\SomeFolder\$1\*.*" 0 next ; Skip files
DetailPrint "$1 is a folder in $InstDir\SomeFolder"
SetOutPath "$InstDir\SomeFolder\$1"
Goto end ; This stops the search at the first folder it finds
next:
FindNext $0 $1
goto loop
end:
FindClose $0
FileFunc.nsh中的Locate宏是基于FindFirst / FindNext构建的,如果您喜欢它的语法,也可以使用...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.