vbs创建日志文件并追加内容

原创
2016/07/10 19:53
阅读数 2.7K
'创建文件

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set ObjFolder = objFSO.CreateTextFile("C:\FSO\FSO.txt")

'往文件里写内容

LogFile = "C:\FSO\FSO.txt"
Const ForWriting = 2 '2为重写文件,8为追加
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(LogFile,ForWriting)
objFile.WriteLine "beginning process  " &Now
objFile.WriteLine "working on process  "&Now
objFile.WriteLine "Process completed at  "&Now

objFile.Close
MsgBox "写入完成"

'验证文件是否存在

LogFile = "C:\FSO\FSO.txt"
Const ForAppending = 8

Set objFSO = CreateObject("Scripting.FileSystemObject")
 If objFSO.FileExists(LogFile) Then
    MsgBox LogFile&"  存在,执行写操作步骤"
    Set objFile = objFSO.OpenTextFile(LogFile,ForAppending)
        objFile.Write "appending  "&Now
    MsgBox "成功写入"
 Else
    MsgBox LogFile&" 不存在,执行先创建此文件,然后写操作"
    Set objFile = objFSO.CreateTextFile(LogFile)
        objFile.Write "writing to new file  "&Now
    MsgBox "创建并写入成功"
 End If

 

展开阅读全文
vbs
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部