1: Option Explicit
2:
3: Call Main()
4:
5: Sub Main()
6:
7: Dim cmdArgs, logFiles, logFile, logFolder, fso, isImported
8: Dim currentLogFileName, currentExtension, fullLogFilePath
9: Dim allowedExtension
10:
11: allowedExtension = "log"
12:
13: Set cmdArgs = WScript.Arguments
14: logFolder = cmdArgs(0)
15:
16: Set fso = CreateObject("Scripting.FileSystemObject")
17:
18: If Not IsNull(logFolder) Then
19: If Not IsEmpty(logFolder) Then
20:
21: Set logFiles = GetFiles(logFolder)
22:
23: currentLogFileName = GetCurrentLogFile()
24: currentLogFileName = GetFullPath(logFolder, currentLogFileName)
25:
26: WScript.Echo "Current Log File " + currentLogFileName
27:
28: For Each logFile in logFiles
29:
30: fullLogFilePath = logFile 'GetFullPath(logFolder, logFile)
31:
32: WScript.Echo "Analyzing File Name: " + logFile + vbCrLf
33:
34: currentExtension = Right(logFile,3)
35:
36: If currentLogFileName <> logFile And currentExtension=allowedExtension Then
37:
38:
39: isImported = RunLogParser(fullLogFilePath)
40:
41: If IsImported Then
42:
43: DeleteFile(fullLogFilePath)
44:
45: End If
46: End If
47:
48: Next
49:
50:
51: End If
52: End If
53:
54: Set fso = Nothing
55:
56: End Sub
57:
58: Function GetFullPath(folderPath, fileName)
59:
60: If Right(folderPath,1) <> "\" Then
61:
62: folderPath = folderPath + "\"
63:
64: End If
65:
66: GetFullPath = folderPath + fileName
67:
68: End Function
69:
70: Function GetFiles(strFolder)
71: Dim fso, fld
72: Set fso = CreateObject("Scripting.FileSystemObject")
73: Set fld = fso.GetFolder(strFolder)
74: Set GetFiles = fld.Files
75: Set fso = Nothing
76: Set fld = Nothing
77: End Function
78:
79: Function DeleteFile(strFileName)
80: Dim fso, fil
81: Set fso = CreateObject("Scripting.FileSystemObject")
82: Set fil = fso.getfile(strFileName)
83: fil.Attributes = 0
84: fil.Delete
85: Set fil = Nothing
86: Set fso = Nothing
87: End Function
88:
89: Function GetCurrentLogFile()
90:
91: Dim currentDate, currentYear, currentMonth, currentDay, currentLogFileName
92:
93: currentDate = Now()
94:
95: currentYear = Right(CStr(Year(currentDate)),2)
96: currentMonth = CStr(Month(currentDate))
97: If Month(currentDate) < 10 Then
98: currentMonth = "0" & currentMonth
99: End If
100: 'currentMonth = Month(currentDate)
101: currentDay = CStr(Day(currentDate))
102: If Day(currentDate) < 10 Then
103: currentDay = "0" & currentDay
104: End If
105:
106: currentLogFileName = "ex" + currentYear + currentMonth + currentDay + ".log"
107:
108: GetCurrentLogFile = currentLogFileName
109:
110:
111: End Function
112:
113: Function RunLogParser(logFile)
114:
115: Dim oShell, iRC, ShellString
116:
117: WScript.Echo "Importing File " + logFile + vbCrLf
118:
119: ShellString = """C:\Program Files\Log Parser 2.2\LogParser.exe"" ""SELECT * INTO IISLogs FROM " + logFile + """ " + " -i:W3C -o:SQL -server:DEV-S04 -database:Logs -driver:""SQL Server"" -username:euclidlogs -password:euclidlogspassword -createTable:OFF "
120:
121: 'WScript.Echo vbTab + "Shell String " + ShellString + vbCrLf
122:
123: Set oShell = WScript.CreateObject("WScript.Shell")
124:
125: iRC = oShell.Run(Shellstring, 1, True)
126:
127: RunLogParser = (iRC=0)
128: 'RunLogParser = False
129: End Function