简体   繁体   English

NSIS-将文件安装到预先存在的不确定子文件夹中?

[英]NSIS - Install a file to a pre-existing, uncertain subfolder?

I'm trying to install a file to a pre-existing folder structured like this: 我正在尝试将文件安装到结构如下的现有文件夹中:

$APPDATA/somefolder/(uncertainFolder)

The "uncertainFolder" would be either "1.0" or "2.0". “ uncertainFolder”将为“ 1.0”或“ 2.0”。

The same file will be installed into the "uncertainFolder" despite the folder name difference. 尽管文件夹名称不同,相同的文件也将安装到“ uncertainFolder”中。 How can I achieve this? 我该如何实现?

Thank you in advance. 先感谢您。

Files installed with the File instruction are extracted into the directory set by SetOutPath . 使用File指令安装的File被提取到SetOutPath设置的目录中。 Changing this path at run-time is not a problem once you know which folder you want. 一旦知道所需的文件夹,就可以在运行时更改此路径。

If the possible folder names are known at compile-time you can use if/or if/else: 如果在编译时已知可能的文件夹名称,则可以使用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}

You can also enumerate files and folders at run-time: 您还可以在运行时枚举文件和文件夹:

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

The Locate macro in FileFunc.nsh is built on top of FindFirst/FindNext and can also be used if you prefer its syntax... FileFunc.nsh中的Locate宏是基于FindFirst / FindNext构建的,如果您喜欢它的语法,也可以使用...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM