0

我有一个字符串变量名,$1其中是一个路径(一个目录)。我需要$1在安装期间将文件从我的输出目录复制到。所以我喜欢这样:

SetOutPath $1
File "Database\*.xxx"

那是从Database文件夹到$1所有类型的文件.xxx。但我只有一个这种类型的文件。如何在另一个变量中获取该文件的名称?

例如,我的Database文件夹如下所示:

Database -> 224eadf234.xxx

我不想224eadf234.xxx在 nsis 脚本中硬编码基本名称,因为将来它可能是其他名称,但扩展名将.xxx始终存在。这就是我寻求*.xxx方法的原因。但我确实需要在运行时获取文件的名称。由于目录中只有这样的文件,Database我认为它会很容易。

谢谢。

4

1 回答 1

1
!appendfile "$%temp%\tmp1234.xxx" "This is a test" ; Create dummy file

; Find file at compile-time (on Windows)
!tempfile NSH
!system 'for %A IN ("$%temp%\*.xxx") DO echo !define THEFILE "%~A" > "${NSH}"'
!include "${NSH}"
!delfile "${NSH}"
!undef NSH
!error "FILE=${THEFILE}"

Section
!include LogicLib.nsh
StrCpy $1 $instdir\test
SetOutPath $1
File "$%temp%\*.xxx"

; Find file at run-time
FindFirst $2 $3 "$1\*.xxx"
${If} $3 != ""
    DetailPrint "First *.xxx file = $3"
${EndIf}
FindClose $2
SectionEnd
于 2013-07-06T19:46:25.927 回答