2017-05-05 12 views
0

私は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)。現在の日付のパラメータを作成する方法がわかりません。ここでVBScriptで現在の日のログを取り出す方法

は、私がこれまで持っているものです。

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 

答えて

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 
+0

ありがとうございました! – liquidsgi

関連する問題