NSIS获取文件路径的最后一个字符串
NSIS to get the last string of the file path
如何从NSIS语言的字符串中只获取jre1.8.0_91?
String "C:\Program Files\Java\jre1.8.0_91"
@Vinod 希望您使用的是最新版本的 NSIS。此外,包括带有 NSIS (nsh.zip) 的最新版本 headers,或包括 WordFind 函数
!include "WordFunc.nsh"
在您的 .nsi 脚本中。
这样您就可以使用 WordFind 函数从文件路径 (C:\Program Files\Java\jre1.8.0_91 在你的例子中)像这样:
${WordFind} "${FilePath}" "\" "-1" $R0
$R0 将包含文件路径中的最后一个 "word" (jre1.8.0_91)。
这是通过使用反斜杠(“\”)作为字符串的分隔符,并选择第一个单词,从字符串末尾倒数(“-1”)来实现的。
NSIS 中的每个字符串操作都可以用StrCpy
、StrCmp
和StrLen
编码。你可以尝试这样的事情:
!macro PathGetFilename path outvar
Push "${path}"
Call PathGetFilename
Pop ${outvar}
!macroend
Function PathGetFilename
Exch
Push
Push
StrCpy ""
loop:
IntOp - 1
StrCpy [=10=] 1
StrCmp [=10=] "" done
StrCmp [=10=] '\' +3
StrCmp [=10=] '/' +2
Goto loop
IntOp + 1
IntCmp 0 "" +2 +2
StrCpy "" ; Ended with slash, return empty string
StrCpy ""
done:
Pop
Pop
Exch
FunctionEnd
Section
!insertmacro PathGetFilename "c:\test" [=10=]
DetailPrint |[=10=]|
!insertmacro PathGetFilename "c:\foo/bar" [=10=]
DetailPrint |[=10=]|
!insertmacro PathGetFilename "nameonly" [=10=]
DetailPrint |[=10=]|
!insertmacro PathGetFilename "\endslash\" [=10=]
DetailPrint |[=10=]|
SectionEnd
如何从NSIS语言的字符串中只获取jre1.8.0_91?
String "C:\Program Files\Java\jre1.8.0_91"
@Vinod 希望您使用的是最新版本的 NSIS。此外,包括带有 NSIS (nsh.zip) 的最新版本 headers,或包括 WordFind 函数
!include "WordFunc.nsh"
在您的 .nsi 脚本中。
这样您就可以使用 WordFind 函数从文件路径 (C:\Program Files\Java\jre1.8.0_91 在你的例子中)像这样:
${WordFind} "${FilePath}" "\" "-1" $R0
$R0 将包含文件路径中的最后一个 "word" (jre1.8.0_91)。
这是通过使用反斜杠(“\”)作为字符串的分隔符,并选择第一个单词,从字符串末尾倒数(“-1”)来实现的。
NSIS 中的每个字符串操作都可以用StrCpy
、StrCmp
和StrLen
编码。你可以尝试这样的事情:
!macro PathGetFilename path outvar
Push "${path}"
Call PathGetFilename
Pop ${outvar}
!macroend
Function PathGetFilename
Exch
Push
Push
StrCpy ""
loop:
IntOp - 1
StrCpy [=10=] 1
StrCmp [=10=] "" done
StrCmp [=10=] '\' +3
StrCmp [=10=] '/' +2
Goto loop
IntOp + 1
IntCmp 0 "" +2 +2
StrCpy "" ; Ended with slash, return empty string
StrCpy ""
done:
Pop
Pop
Exch
FunctionEnd
Section
!insertmacro PathGetFilename "c:\test" [=10=]
DetailPrint |[=10=]|
!insertmacro PathGetFilename "c:\foo/bar" [=10=]
DetailPrint |[=10=]|
!insertmacro PathGetFilename "nameonly" [=10=]
DetailPrint |[=10=]|
!insertmacro PathGetFilename "\endslash\" [=10=]
DetailPrint |[=10=]|
SectionEnd