zoukankan      html  css  js  c++  java
  • 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 $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 是一个变量,这里相当于文件句柄。
    注意打开文件的方式选择,如果不需要覆盖原文件内容,则使用追加方式打开。

  • 相关阅读:
    Android基站定位
    删除远程分支
    docker的相关使用
    [整理]-端口的概念、常用端口及其对应服务
    [转]-nohup-真正的Shell后台运行
    转- 在ubuntu下安装Nginx
    转: 命名关键字参数
    远程SCP报错,报22号口错误
    vim保存时提示: 无法打开并写入文件
    如何处理导出的csv无法查看身份证后三位的情况?
  • 原文地址:https://www.cnblogs.com/njabsky/p/14069028.html
Copyright © 2011-2022 走看看