nsis从txt文件读取目录?

nsis从txt文件读取目录?,nsis,Nsis,我正在尝试从文本文件读取目录,但它不工作 txt是一个两行文件,每个目录一行 有人能帮我吗 ; example1.nsi ; ; This script is perhaps one of the simplest NSIs you can make. All of the ; optional settings are left to their default settings. The installer simply ; prompts the user asking them whe

我正在尝试从文本文件读取目录,但它不工作


txt是一个两行文件,每个目录一行

有人能帮我吗

; example1.nsi
;
; This script is perhaps one of the simplest NSIs you can make. All of the
; optional settings are left to their default settings. The installer simply 
; prompts the user asking them where to install, and drops a copy of example1.nsi
; there. 

;--------------------------------

; The name of the installer
Name "Example1"

; The file to write
OutFile "example1.exe"

; The default installation directory
InstallDir $DESKTOP

; Request application privileges for Windows Vista
RequestExecutionLevel admin
!include "LogicLib.nsh"
!include FileFunc.nsh
ShowInstDetails show


;--------------------------------

; Pages


;--------------------------------


Function .onInit



functionend

; The stuff to install
Section "" ;No components page, name is not important
FileOpen $0 "test.txt" r
;FileSeek $4 1000 ; we want to start reading at the 1000th byte
FileRead $0 $1 ; we read until the end of line (including carriage return and new line) and save it to $1
FileRead $0 $2
;FileRead $4 $2 10 ; read 10 characters from the next line
FileClose $0 ; and close the file
DetailPrint $1
DetailPrint $2


CopyFiles $1 "D:\Desktop\taobao"
  ; Set output path to the installation directory.
SetOutPath $INSTDIR


SectionEnd ; end the section
FileOpen$0“test.txt”r
有两个问题

  • 您没有使用完整路径
  • 我假设最终用户计算机上不存在此文件。在阅读之前,您可能需要从安装程序中提取它
  • 另一个问题是
    FileRead
    在返回的字符串中包含换行符,如果不需要,则必须将其删除。换行符在Windows上的路径中无效

    ; Create simple text file for this example:
    !delfile /nonfatal "myexample.txt"
    !appendfile "myexample.txt" "Hello$\r$\n"
    !appendfile "myexample.txt" "W o r l d$\r$\n"
    
    !include "StrFunc.nsh"
    ${StrTrimNewLines} ; Tell StrFunc.nsh to define this function for us
    
    Section
    SetOutPath $InstDir
    
    InitPluginsDir ; Make sure $PluginsDir exists (it is automatically deleted by the installer when it quits)
    File "/oname=$PluginsDir\data.txt" "myexample.txt" ; Extract our myexample.txt file to $PluginsDir\data.txt
    
    FileOpen $0 "$PluginsDir\data.txt" r
    FileRead $0 $1
    ${StrTrimNewLines} $1 $1
    FileRead $0 $2
    ${StrTrimNewLines} $2 $2
    FileClose $0
    DetailPrint "Line 1=$1"
    DetailPrint "Line 2=$2"
    SectionEnd
    

    test.txt是一个两行文件,每行每目录,实际问题是什么?1美元和2美元是空的吗?为什么跳过1000字节?为什么被评论掉了?非常感谢!问题是换行符!