02_NSIS檔案開讀寫功能
02_NSIS檔案開讀寫功能
#NSIS檔案開讀寫功能
!include “LogicLib.nsh” !include “WordFunc.nsh” OutFile “02.exe” ShowInstDetails show #1016 Information Section “” #SetAutoClose true #instpage autoclose DetailPrint “#Open File and write string into file”#顯示目前進度 FileOpen $0 “$EXEDIR\FileOption.txt” w #開新檔在安裝程式目錄中 FileWrite $0 “Where there is a will there is a way!$\r$\n”#寫入資訊 FileClose $0 #關閉檔案 DetailPrint “#Open file with add mode”#顯示目前進度 FileOpen $0 “$EXEDIR\FileOption.txt” a #開啟舊檔 FileWrite $0 “Never put off till tomorrow what may be done today!$\r$\n”#寫入資訊 FileClose $0 #關閉檔案 DetailPrint “#You will find the string had overwrite,so you must seek end of file”#顯示目前進度 FileOpen $0 “$EXEDIR\FileOption.txt” a #開啟舊檔 FileSeek $0 0 END #移動檔案旗標 FileWrite $0 “String append into file$\r$\n” #寫入資訊 FileClose $0 #關閉檔案 DetailPrint “#Read file string,note: must less than 1024byte”#顯示目前進度 FileOpen $0 “$EXEDIR\FileOption.txt” r #開啟舊檔 ${Do} FileRead $0 $1 #讀取檔案 DetailPrint $1 ${LoopWhile} $1 != “” /*#you can also do like this. ${Do} FileRead $0 $1 DetailPrint $1 ${If} $1 == “” ${ExitDo} ${EndIf} ${Loop} */ DetailPrint “#List file name and echo” #顯示目前進度 FindFirst $0 $1 “$EXEDIR\*.txt” #搜尋目錄下所有文字檔 ${While} $1 != “” DetailPrint $1 FindNext $0 $1 ${EndWhile} DetailPrint “” #搜索目前的目錄下所有.txt檔裡,輸出包含”nsis”字串的檔案名 FindFirst $0 $1 “$EXEDIR\*.txt” ${While} $1 != “” #DetailPrint $1 FileOpen $3 “$EXEDIR\$1” r ${Do} FileRead $3 $4 #DetailPrint $4 ${WordFind} $4 “nsis” “*” $R0 ${If} $R0 > 0 DetailPrint “#Find string $\”nsis$\” in this file $1#” ${ExitDo} ${EndIf} ${LoopWhile} $4 != “” FindNext $0 $1 ${EndWhile} SectionEnd |