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

所属分类: 脚本专栏 / vbs 阅读数: 724
收藏 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教程:函数-LCase 函数

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

VBS教程:函数-LBound 函数

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

VBS教程:函数-Join 函数

返回一个字符串,此字符串由包含在数组中的许多子字符串联接创建
收藏 0 赞 0 分享

VBS教程:函数-IsObject 函数

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

VBS教程:函数-IsNumeric 函数

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

VBS教程:函数-IsNull 函数

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

VBS教程:函数-IsEmpty 函数

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

VBS教程:函数-IsDate 函数

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

VBS教程:函数-IsArray 函数

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

VBS教程:函数-Int、Fix 函数

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