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."
rutgermonsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Open in new window

0
rutgermonsAuthor Commented:
Hi Graham

thanks for the response, however the filename is erroring, can you help?
0
Bill PrewCommented:
Looks like it should work, what error are you getting, and on what line number?

~bp
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

rutgermonsAuthor Commented:
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"
0
GrahamSkanRetiredCommented:
I didn't bother to check your original code, but in doing so, I find it confusing. Does it actually work?
0
rutgermonsAuthor Commented:
Yes,the only thing missing is to assign the file name
0
Bill PrewCommented:
This looks like a problem:

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)

Open in new window

Notice that inside the loop you are reusing the same variable name that the for each loops over, that's bad.  Change the objFile that you set inside the loop to a different name, like this:

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 objLogFile = objFSO.OpenTextFile(objFile.Path, intForReading, False)
                'loop thorugh log file
                Do While Not objLogFile.AtEndOfStream
                        strData = objLogFile.ReadLine
                        If InStr(strData, "connected") Or InStr(strData, "refused") Then objOut.WriteLine strData & ", " & objFile.Name & ", " & Date & ", " & Time & ""
                Loop

                objLogFile.Close
                Set objLogFile = Nothing
        End If
Next
objOut.Close
'MsgBox "Finished." 

Open in new window

~bp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rutgermonsAuthor Commented:
brilliant, works,thanks a lot
0
GrahamSkanRetiredCommented:
Sorry. I doubt the statement in your comment #39578002 that the original code worked, so any fix was not obvious.
0
rutgermonsAuthor Commented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.