'Check for correct number of arguments
If WScript.Arguments.length <> 2 Then
WScript.Echo "Usage: cscript.exe CheckLog.vbs LogFile InputFile" & _
vbCrLf & vbCrLf & "LogFile: Report log file." & vbCrLf & _
"InputFile: List of report names that should appear in LogFile " & _
"(one name per line)."
WScript.Quit 1
End If'Dim the variables we're going to use
Dim WshShell, strWorkDir, numFiles, numFolders, fso, logFilePath
Dim logFile, inputFilePath, inputFile, resultFile, today
Dim logFileText, inputFileText, reportNames, val
'Some useful constants
Const ForReading = 1, ForWriting = 2
'Create the almighty shell and FSO
set WshShell = WScript.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
'Get file names from command line
logFilePath = WScript.Arguments(0)
inputFilePath = WScript.Arguments(1)
'Make sure the files exist
If logFilePath = "" Or Not fso.FileExists(logFilePath) Then
WScript.Echo "Invalid LogFile specified."
WScript.Quit 1
End If
'And again...
If inputFilePath = "" Or Not fso.FileExists(inputFilePath) Then
WScript.Echo "Invalid InputFile specified."
WScript.Quit 1
End If
'Begin scan
WScript.Echo "Starting scan..." & vbCrLf
'Format today's date
today = Year(Date) & "-" & Month(Date) & "-" & Day(Date)
'Open the three files we're going to use
Set logFile = fso.OpenTextFile(logFilePath, ForReading)
Set inputFile = fso.OpenTextFile(inputFilePath, ForReading)
Set resultFile = fso.OpenTextFile(today & " Report Log.log", ForWriting, true)
'Start results file with the date
resultFile.WriteLine("Missing Reports for " & today & ":" & vbCrLf)
'Read in the two input files
logFileText = logFile.ReadAll()
inputFileText = inputFile.ReadAll()
'Split the names file into an array
reportNames = Split(inputFileText, vbCrLf, -1, 1)
'For every name in the array, check and see if it's in the report log
For Each name In reportNames
val = InStr(1, logFileText, name, 1)
If val = 0 Or val = Null Then
WScript.Echo "Report '" & name & "' not found."
resultFile.WriteLine(name)
End If
Next
'Finish up
resultFile.WriteLine(vbCrLf & "End Scan")
WScript.Echo vbCrLf & "Finished."
'Clean up
inputFile.close
logFile.close
resultFile.close
Set fso = Nothing
Set resultFile = Nothing
Set logFile = Nothing
Set inputFile = Nothing