Nsis:当路径包含变量时,文件命令找不到文件

时间:2018-12-13 02:54:28

标签: file nsis

有我的代码 !define InputDir "D:\a" !define OutDir "D:\Temp2" StrCpy $R0 "T1" SetOutPath "${OutDir}\$R0" File /r "${InputDir}\$R0\*.*" 在“ D:\ a”中有两个目录T1T2。T1的目录中有文件。 但是当我运行它时,它显示“文件:D:\ a \ $ R0 *。*->找不到文件” 显然,该命令找不到变量。当我仅知道包含目录名称的var时,是否有任何方法获取文件?谢谢。

1 个答案:

答案 0 :(得分:0)

File是在编译时和运行时都执行的混合函数!

您不能在File指令中使用变量,只能定义:

!define srcdir "c:\myfiles"

OutFile Test.exe

Page Directory
Page InstFiles

Section
SetOutPath $InstDir
File /r "${srcdir}\*.*"
SectionEnd

当安装程序在最终用户计算机上运行时,变量会扩展,但是编译器在压缩本地计算机上的文件时需要知道文件路径。

如果您想做一些特别的事情,那么您必须使用!system来执行一个外部工具/脚本,该工具会生成您想要的指令,您可以!include

InstallDir $Temp\InstTest
Page Directory
Page InstFiles

; Build dummy directory tree for this example:
!system 'md %temp%\test\1\2\3\4'
!system 'md %temp%\test\a\b'
!appendfile '$%temp%\test\a\file.txt' "Hello$\n"

; Build batch file
!appendfile "$%temp%\nsistmp.cmd" '@ECHO OFF&SETLOCAL ENABLEEXTENSIONS DISABLEDELAYEDEXPANSION$\r$\n'
!appendfile "$%temp%\nsistmp.cmd" 'SET nsh=%~1&SET dst=%~2&GOTO s$\r$\n'
!appendfile "$%temp%\nsistmp.cmd" ':enum$\r$\n'
!appendfile "$%temp%\nsistmp.cmd" 'FOR /D %%A IN ("%~1\%~2\*") DO ((>> "%nsh%" ECHO CreateDirectory "%dst%\%~2\%%~nA") & CALL %0 "%~1" "%~2\%%~nA")$\r$\n'
!appendfile "$%temp%\nsistmp.cmd" '@GOTO :EOF$\r$\n'
!appendfile "$%temp%\nsistmp.cmd" ':s$\r$\n'
!appendfile "$%temp%\nsistmp.cmd" 'CALL :enum "%~3" "."$\r$\n'

; Execute batch and include the result:
Section
SetOutPath $InstDir
!tempfile nsh
!system '"$%temp%\nsistmp.cmd" "${nsh}" $InstDir "%temp%\test"'
!delfile "$%temp%\nsistmp.cmd"
!include "${nsh}"
!delfile "${nsh}"
SectionEnd
相关问题