vbs脚本:WriteText
2010年08月09日
Rem : =========== 写入多行文本,会覆盖文件中已有的内容 Rem : =========== 文件必须存在 Rem : =========== text 中可以是单行,也可以是多行文本, Sub WriteText( file, text ) Dim f f = Trim( file ) IfRight(f,1) = "\" Then f = Left(f,Len(f) -1 )If fso.fileexists(f) = False ThenErr.Raise vbObjectError+128, "WriteText", f & " does not exists" Dim errMsg OnError Resume NextRem ====== code begin Const ForReading = 1, ForWriting = 2 Dim fi Set fi = fso.OpenTextFile(f, ForWriting, True) fi.Write text fi.close Rem ====== code endIfErr.Number 0 Then errMsg = Err.Description OnError Goto 0 Err.Raise vbObjectError+128, "WriteText", errMsg & vbNewLine & _ " file:" & vbTab & file & vbNewLine & _ " text:" & vbTab & text ExitSubEndIfEndSub
2010年08月09日
Rem : =========== 写入多行文本,会覆盖文件中已有的内容 Rem : =========== 文件必须存在 Rem : =========== text 中可以是单行,也可以是多行文本, Sub WriteText( file, text ) Dim f f = Trim( file ) IfRight(f,1) = "\" Then f = Left(f,Len(f) -1 )If fso.fileexists(f) = False ThenErr.Raise vbObjectError+128, "WriteText", f & " does not exists" Dim errMsg OnError Resume NextRem ====== code begin Const ForReading = 1, ForWriting = 2 Dim fi Set fi = fso.OpenTextFile(f, ForWriting, True) fi.Write text fi.close Rem ====== code endIfErr.Number 0 Then errMsg = Err.Description OnError Goto 0 Err.Raise vbObjectError+128, "WriteText", errMsg & vbNewLine & _ " file:" & vbTab & file & vbNewLine & _ " text:" & vbTab & text ExitSubEndIfEndSub