'调用 添加日志函数
writing "C:\Users\lcy\Desktop\UFTtest\logs\logs.txt","hello word!"
'调用函数,存在两个参数:文件所在路径\添加日志内容
Function writing(filepath,logs)
Dim fso,file
'定义常量
Const forreading = 1,forwriting =2,forappending= 8
'创建一个文件对象
Set fso = CreateObject("scripting.filesystemobject")
'判断文件对象是否存在
If fso.FileExists(filepath)=False Then
'创建日志文件
Set file =fso.CreateTextFile(filepath)
End If
'打开日志文件,false的情况,是本地没有文件,需要创建
Set file = fso.OpenTextFile(filepath,forappending,false)
'添加日志内容,vbcrlf 为回车换行标识符
file.Write(vbcrlf&logs)
'关闭文件
file.Close
'释放文件空间
Set fso = Nothing
End function