Link to home
Start Free TrialLog in
Avatar of rutgermons
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.FileSystemObject")
Const intForReading = 1
 
 'create output file
 strOutputName = "output.txt"
 Set objOut = objFSO.GetFolder(strFolder).CreateTextFile(strOutputName, 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(objFile.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."
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Change the WriteLine line:
objOut.WriteLine strData & ", " & objFile.Name & ", " & Date & ", " & Time

Open in new window

Avatar of rutgermons
rutgermons

ASKER

Hi Graham

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
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"
I didn't bother to check your original code, but in doing so, I find it confusing. Does it actually work?
Yes,the only thing missing is to assign the file name
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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