欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 综合教程 >内容正文

综合教程

NSIS FileOpen打开读写文件操作

发布时间:2023/12/19 综合教程 39 生活家
生活随笔 收集整理的这篇文章主要介绍了 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打开读写文件操作的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。