QTP调用vbs脚本写入日志

本文介绍了一个使用VBScript实现的日志记录脚本。该脚本能够将指定的内容写入到日志文件中,并支持日志文件的追加及创建日志文件夹等功能。通过调用不同的函数,可以灵活地进行日志管理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Option Explicit
'==========================================================================
' 脚本说明: 写入日志文件
'
' AUTHOR: 孙强
' DATE  : 2009-12-8
'
' COMMENT:
'
'==========================================================================
'调用写入日志文件入口
'==========================================================================
'Dim sFoldername,sComtenet
'sFoldername = "D:/temp/"
'sComtenet = "测试脚本调用"
'WriteLog sFoldername,sComtenet
'==========================================================================
' 写入日志文件入口
'==========================================================================
Function WriteLog(sFoldername,sComtenet)
Dim LogTime,sFilename
LogTime = FormatDateTime(Date, 0)&" "&Time&"-------"
sComtenet = LogTime&sComtenet
sFilename = sFoldername&"/QTPlog.txt"
Dim oFSO
'创建文件系统对象
Set oFSO = CreateObject ("Scripting.FileSystemObject")
Dim CheckFolderExists,CheckfileExists
'检查日志存放文件夹是否存在
CheckFolderExists = oFSO.FolderExists(sFoldername)
If CheckFolderExists = True Then
  '检查日志文件是否存在
  CheckfileExists = oFSO.FileExists(sFilename)
   If CheckfileExists = True Then
     AppendToFile sFilename,sComtenet
 Else WriteToFile sFilename,sComtenet
 End If
Else CreateFolderDemo sFoldername
  WriteToFile sFilename,sComtenet
End If
End Function
'==========================================================================
' 追加Log文件
'==========================================================================
Function AppendToFile(sFilename, sComtenet)
  Dim fso,OpenFile
  Const ForReading = 1, ForWriting = 2, ForAppending = 8
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set OpenFile = fso.OpenTextFile(sFilename, ForAppending, True)
    OpenFile.WriteLine(sComtenet)
    OpenFile.Close
End Function
'==========================================================================
'写入Log文件
'==========================================================================
Function WriteToFile(sFilename, sComtenet)
  Dim fso,CreateFile
  Set fso = CreateObject("Scripting.FileSystemObject")
   Set CreateFile = fso.CreateTextFile(sFilename, True)
   CreateFile.WriteLine(sComtenet)
   CreateFile.Close
End Function
'==========================================================================
'创建文件夹
'==========================================================================
Function CreateFolderDemo(sFlodername)
  Dim fso, f
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set f = fso.CreateFolder(sFlodername)
End Function

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值