如何在VBScript中提取当天的日志

时间:2017-05-05 19:09:55

标签: vbscript

我是VBScript的新手,我需要一些脚本帮助。我需要在VBScript中每天只提取3个文件。现在我的脚本从C:\ Windows \ Logs \ WindowsServerBackup中提取所有内容但我需要将拉力限制为仅当前天数(Backup-05-05-2017_11-06-13.log,Backup_Operations-05-05-2017_17 -52-06.log和Backup_Error-05-05-2017_17-56-06.log)。我不知道如何为当前日期创建参数。

这是我到目前为止所做的:

Option Explicit

Const c_RoboLogDirectory = "D:\RoboLogs"
Const c_LogFileDirectory = "C:\Windows\Logs\WindowsServerBackup"

Dim fldLogFiles
Dim flsLogFiles
Dim fldRoboLogs
Dim flsRoboLogs
Dim objEmail
Dim objFSO
Dim strFile
Dim strFile1

objEmail.From = c_Sender
objEmail.To = c_Receiver
objEmail.Subject = c_Subject

' get all the files within the folder and attach them to the email
Set objFSO = CreateObject("Scripting.FileSystemObject")

Set fldLogFiles = objFSO.GetFolder(c_LogFileDirectory)
Set flsLogFiles = fldLogFiles.Files

Set fldRoboLogs = objFSO.GetFolder(c_RoboLogDirectory)
Set flsRoboLogs = fldRoboLogs.Files

For Each strFile In flsLogFiles
    objEmail.AddAttachment strFile
Next

For Each strFile1 In flsRoboLogs
    objEmail.AddAttachment strFile1
Next

1 个答案:

答案 0 :(得分:0)

从今天开始构建一个字符串:

Function Pad(num)
    Pad = Right("00" & num, 2)
End Function

today   = Date
datestr = Pad(Month(today)) & "-" & Pad(Day(today)) & "-" & Year(today)

并且仅在文件名包含该字符串时附加文件:

If InStr(strFile.Name, datestr) > 0 Then
    objEmail.AddAttachment strFile
End If