rutgermons
asked on
vb script time / date /filename
folks
how do I add the file name , date and time to the log file in the below statement? also ensure these have comma delimiters in them
strFolder = "C:\test"
Dim objFSO
Dim objFile
Dim objOut
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
Const intForReading = 1
'create output file
strOutputName = "output.txt"
Set objOut = objFSO.GetFolder(strFolder ).CreateTe xtFile(str OutputName , True)
'for each file in directory
For Each objFile In objFSO.GetFolder(strFolder ).Files
'if its a log file
If Right(LCase(objFile.Name), 4) = ".log" Then
'open log file
Set objFile = objFSO.OpenTextFile(objFil e.Path, intForReading, False)
'loop thorugh log file
Do While Not objFile.AtEndOfStream
strData = objFile.ReadLine
If InStr(strData, "connected") Or InStr(strData, "refused") Then objOut.WriteLine strData
Loop
objFile.Close
End If
Next
objOut.Close
'MsgBox "Finished."
how do I add the file name , date and time to the log file in the below statement? also ensure these have comma delimiters in them
strFolder = "C:\test"
Dim objFSO
Dim objFile
Dim objOut
Set objFSO = CreateObject("Scripting.Fi
Const intForReading = 1
'create output file
strOutputName = "output.txt"
Set objOut = objFSO.GetFolder(strFolder
'for each file in directory
For Each objFile In objFSO.GetFolder(strFolder
'if its a log file
If Right(LCase(objFile.Name),
'open log file
Set objFile = objFSO.OpenTextFile(objFil
'loop thorugh log file
Do While Not objFile.AtEndOfStream
strData = objFile.ReadLine
If InStr(strData, "connected") Or InStr(strData, "refused") Then objOut.WriteLine strData
Loop
objFile.Close
End If
Next
objOut.Close
'MsgBox "Finished."
ASKER
Hi Graham
thanks for the response, however the filename is erroring, can you help?
thanks for the response, however the filename is erroring, can you help?
Looks like it should work, what error are you getting, and on what line number?
~bp
~bp
ASKER
bill
If InStr(strData, "connected") Or InStr(strData, "refused") Then objOut.WriteLine strData & ", " & objFile.Name & ", " & Date & ", " & Time & ""
runtime error 438 line
"object does not support property or method"
If InStr(strData, "connected") Or InStr(strData, "refused") Then objOut.WriteLine strData & ", " & objFile.Name & ", " & Date & ", " & Time & ""
runtime error 438 line
"object does not support property or method"
I didn't bother to check your original code, but in doing so, I find it confusing. Does it actually work?
ASKER
Yes,the only thing missing is to assign the file name
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
brilliant, works,thanks a lot
Sorry. I doubt the statement in your comment #39578002 that the original code worked, so any fix was not obvious.
ASKER
it did albeit not provide the filename and time and date, bill perfectly advised on an improvement and presented a better solution which works soundly
Open in new window