vbs向指定的文件添加内容

'向指定的文件写字符串,第三个参数指定是否删除原来的内容
Function Z_WriteFile(sFileName, sText, bAppend)
    Dim fs, fso, iomode
    if bAppend = True Then
        iomode = 8              'ForAppending
    else
        iomode = 2              'ForWriting
    end if
    set fs = CreateObject("Scripting.FileSystemObject")
    set fso = fs.OpenTextFile(sFileName, iomode, True)  '第三个参数表明文件不存在,则新建文件
    fso.WriteLine sText
    fso.Close
    set fso = Nothing
    set fs = Nothing
End Function

Dim path, sFileName, sText
path = "E:\Program\VBScript"
sFileName = path & "\1.txt"
sText = "what can I do for you"
Z_WriteFile sFileName, sText, True

Z_WriteFile中的第三个参数指定向文件末尾添加内容还是清除原来的内容再插入内容。

原文地址:https://www.cnblogs.com/joeblackzqq/p/1967238.html