I have been trying to get this to work but can't figure out my next step. I'm new to vbscript.
Basically I'm writing a log to a directory multiple times a day. I need to Count how many times that log file is created each day, and if it succeded or not. The Log file name has a tag depending on certain results. Here is my code. I'm having problems figuring out how to get the list of files by date, and keep the count going. I would like it to count all the files with a created date of X and then write that count, then go on to a created date of X+1.
On Error Resume Next
Dim fso, folder, files, NewsFile, LogFolder, LogDir, DateTest, createdate
Dim FailCount, DuplicateCount, TNcount, NoResults, VCcount
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Set fso = CreateObject("Scripting.FileSystemObject")
LogFolder = "\\serverpath\Results\"
LogDir = "\\serverpath\Results\"
Set folder = fso.GetFolder(LogFolder)
Set files = folder.Files
VCcount = 0
TNcount = 0
FailCount = 0
DuplicateCount = 0
NoResults = 0
For Each folderIdx In files
' Set DateTest=FSO.GetFile(folderidx.name)
createdate = folderidx.DateCreated
DateTest = (right("00" & month(createdate),2) & "-" & right("00" & day(createdate),2))
Set NewFile = fso.CreateTextFile("c:\Macro\LogReport.txt", True)
' msgbox DateTest
If instr(folderidx.name, "Import Log-TN") > 0 Then
VCcount = VCcount + 1
Elseif Ifinstr(folderidx.name, "Import Log-VC") > 0 Then
TNcount = TNcount + 1
ElseIf Ifinstr(folderidx.name, "Import Log-Fa") > 0 Then
FailCount = FailCount + 1
ElseIf Ifinstr(folderidx.name, "Import Log-Or") > 0 Then
DuplicateCount = DuplicateCount + 1
ElseIf Ifinstr(folderidx.name, "Import Log-Day-") 0 Then
NoResults = NoResults + 1
End if
NewFile.WriteLine(DateTest)
NewFile.WriteLine(FailCount)
NewFile.WriteLine(DuplicateCount)
NewFile.WriteLine(TNcount)
NewFile.WriteLine(VCcount)
NewFile.Close
Basically I'm writing a log to a directory multiple times a day. I need to Count how many times that log file is created each day, and if it succeded or not. The Log file name has a tag depending on certain results. Here is my code. I'm having problems figuring out how to get the list of files by date, and keep the count going. I would like it to count all the files with a created date of X and then write that count, then go on to a created date of X+1.
On Error Resume Next
Dim fso, folder, files, NewsFile, LogFolder, LogDir, DateTest, createdate
Dim FailCount, DuplicateCount, TNcount, NoResults, VCcount
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Set fso = CreateObject("Scripting.FileSystemObject")
LogFolder = "\\serverpath\Results\"
LogDir = "\\serverpath\Results\"
Set folder = fso.GetFolder(LogFolder)
Set files = folder.Files
VCcount = 0
TNcount = 0
FailCount = 0
DuplicateCount = 0
NoResults = 0
For Each folderIdx In files
' Set DateTest=FSO.GetFile(folderidx.name)
createdate = folderidx.DateCreated
DateTest = (right("00" & month(createdate),2) & "-" & right("00" & day(createdate),2))
Set NewFile = fso.CreateTextFile("c:\Macro\LogReport.txt", True)
' msgbox DateTest
If instr(folderidx.name, "Import Log-TN") > 0 Then
VCcount = VCcount + 1
Elseif Ifinstr(folderidx.name, "Import Log-VC") > 0 Then
TNcount = TNcount + 1
ElseIf Ifinstr(folderidx.name, "Import Log-Fa") > 0 Then
FailCount = FailCount + 1
ElseIf Ifinstr(folderidx.name, "Import Log-Or") > 0 Then
DuplicateCount = DuplicateCount + 1
ElseIf Ifinstr(folderidx.name, "Import Log-Day-") 0 Then
NoResults = NoResults + 1
End if
NewFile.WriteLine(DateTest)
NewFile.WriteLine(FailCount)
NewFile.WriteLine(DuplicateCount)
NewFile.WriteLine(TNcount)
NewFile.WriteLine(VCcount)
NewFile.Close