vbs脚本:WriteText

来源:互联网 发布:北京立方米网络 编辑:程序博客网 时间:2024/05/23 15:45
Rem :  ===========  写入多行文本,会覆盖文件中已有的内容Rem :  ===========  文件必须存在Rem :  ===========  text 中可以是单行,也可以是多行文本,Sub WriteText( file, text )Dim ff = Trim( file )If Right(f,1) = "/" Then f = Left(f,Len(f) -1 )If fso.fileexists(f) = False Then Err.Raise vbObjectError+128, "WriteText", f & " does not exists"Dim errMsgOn Error Resume NextRem  ======  code beginConst ForReading = 1, ForWriting = 2Dim fiSet fi = fso.OpenTextFile(f, ForWriting, True)fi.Write textfi.closeRem  ======  code endIf Err.Number <> 0 ThenerrMsg = Err.DescriptionOn Error Goto 0Err.Raise vbObjectError+128, "WriteText", errMsg & vbNewLine & _"                file:" & vbTab & file & vbNewLine & _"                text:" & vbTab & textExit SubEnd IfEnd Sub
原创粉丝点击