vbs向指定的文件添加内容的函数

所属分类: 脚本专栏 / vbs 阅读数: 700
收藏 0 赞 0 分享
复制代码 代码如下:

'向指定的文件写字符串,第三个参数指定是否删除原来的内容
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中的第三个参数指定向文件末尾添加内容还是清除原来的内容再插入内容。
更多精彩内容其他人还在看

VBS教程:函数-Chr 函数

VBS教程:函数-Chr 函数
收藏 0 赞 0 分享

VBS教程:函数-CDbl 函数

VBS教程:函数-CDbl 函数
收藏 0 赞 0 分享

VBS教程:函数-CDate 函数

VBS教程:函数-CDate 函数
收藏 0 赞 0 分享

VBS教程:函数-CCur 函数

VBS教程:函数-CCur 函数
收藏 0 赞 0 分享

VBS教程:函数-CByte 函数

VBS教程:函数-CByte 函数
收藏 0 赞 0 分享

VBS教程:函数-CBool 函数

VBS教程:函数-CBool 函数
收藏 0 赞 0 分享

VBS教程:函数-Atn 函数

VBS教程:函数-Atn 函数
收藏 0 赞 0 分享

VBS教程:函数-Asc 函数

VBS教程:函数-Asc 函数
收藏 0 赞 0 分享

VBS教程:函数-Array 函数

VBS教程:函数-Array 函数
收藏 0 赞 0 分享

VBS教程:函数-Abs 函数

VBS教程:函数-Abs 函数
收藏 0 赞 0 分享
查看更多