NSIS FileOpen打開讀寫文件操作


打開文件 FileOpen
語法:
FileOpen user_var(handle output) filename openmode
 
Opens a file named "filename", and sets the handle output variable with the handle.
打開一個名為“filename”的文件,並使用句柄設置句柄輸出變量。
The openmode should be one of "r" (read) "w" (write, all contents of file are destroyed) or "a" (append, meaning opened for both read and write, contents preserved).
打開方式openmode應該是以下值之一
  • r 讀取
  • w 寫入(會覆蓋原來的內容)
  • a 追加(讀取和寫入均打開,保留了原來的內容)
In all open modes, the file pointer is placed at the beginning of the file.
在所有打開模式下,文件指針都位於文件的開頭。
If the file cannot be opened, the handle output is set to empty, and the error flag is set.
如果無法打開文件,則將句柄輸出設置為空,並設置錯誤標志。
If no absolute path is specified the current folder will be used. The current folder is the folder set using the last  SetOutPath instruction.
如果未指定絕對路徑,則將使用當前文件夾。當前文件夾是使用最后一個 SetOutPath指令設置的文件夾。
If you have not used  SetOutPath the current folder is  $EXEDIR.
如果尚未使用 SetOutPath,則當前文件夾為 $ EXEDIR
 
示例:
FileOpen $0 $INSTDIR\file.dat r
FileClose $0

Command introduced with NSIS v1.60

 
寫入文件 FileWrite
語法:
FileWrite user_var(handle) content
 
關閉文件 FileClose
語法:
FileClose user_var(handle)
 
下面是一個以寫入方式打開文件並重寫內容的示例:
ClearErrors
FileOpen $0 "$INSTDIR\NIRModelingRPF\BusFrontend\static\js\BaseUrl.js" w
IfErrors done
FileWrite $0 'const BASE_URL = { url: "http://$SQL_SERVERNAME:80/NIRModelingAPI/" };const RPF_URL = { url: "http://$SQL_SERVERNAME:80/" };'
FileClose $0
done:

 

 
總結:
FileOpen、FileWrite、FileClose 是三個文件操作函數。
$0 是一個變量,這里相當於文件句柄。
注意打開文件的方式選擇,如果不需要覆蓋原文件內容,則使用追加方式打開。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM