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 lastSetOutPathinstruction.
如果未指定絕對路徑,則將使用當前文件夾。當前文件夾是使用最后一個SetOutPath指令設置的文件夾。
If you have not usedSetOutPaththe current folder is$EXEDIR.
如果尚未使用SetOutPath,則當前文件夾為$ EXEDIR。
示例:
FileOpen $0 $INSTDIRfile.dat r FileClose $0
Command introduced with NSIS v1.60
寫入文件 FileWrite
語法:
FileWrite user_var(handle) content
關閉文件 FileClose
語法:
FileClose user_var(handle)
下面是一個以寫入方式打開文件并重寫內容的示例:
ClearErrors
FileOpen $0 "$INSTDIRNIRModelingRPFBusFrontendstaticjsBaseUrl.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 是一個變量,這里相當于文件句柄。
注意打開文件的方式選擇,如果不需要覆蓋原文件內容,則使用追加方式打開。
總結
以上是生活随笔為你收集整理的NSIS FileOpen打开读写文件操作的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: http 请求 与其同步与异步请求的通透
- 下一篇: android 字定义GridView