Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with writing to file

Status
Not open for further replies.

fAisha

IS-IT--Management
Jan 13, 2010
7
PL
Hi Guys,
I have a problem.
I wolud like to write a script meet requirements:
Script must parse logfile for string ">>ZIP", create new text file with date-based name and copy every line which contains string "Connector".
HELP, PLEASE!!!

I wrote script to parse logfile.
I wrote script to create text file data-based name.
But: I can't write data to this plik. What Can I do wrong?
How to combine this 2 script?

script to parse logfile?
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\ParserIIS\ex091218.log", 1)

Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
If InStr(strLine, "ScomConnector") <> 0 Then
strNewContents = strNewContents & strLine & vbCrLf
End If
Loop
objFile.Close

Set objFile = objFSO.OpenTextFile(C:\ParserIIS\write.txt", 2)
objFile.Write strNewContents
objFile.Close




script to create data-based named file:
Option Explicit
On Error Resume Next

Dim fsoObject, open_File, target_File, thisday
Set fsoObject = WScript.CreateObject("Scripting.FileSystemObject")

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\ParserIIS\ex091218.log", 1)

today_date()
target_File = "C:\ParserIIS\ex" & thisday & ".txt"
Function Today_Date()
thisday=Right(Year(Date),2) & Right("0" & Month(Date),2) & Right("0" & Day(Date),2)
End Function

Open_My_File()


Close_my_File()

Function Open_My_File()
If (fsoObject.FileExists(target_File)) Then
Set open_File = fsoObject.OpenTextFile(target_File, 8)
Else
Set open_File = fsoObject.OpenTextFile(target_File, 2, "True")
End If
End Function

Function Close_My_File()
open_File.Close()
End Function


 
something like this ?
Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\ParserIIS\ex091218.log", 1)
Do Until objFile.AtEndOfStream
    strLine = objFile.ReadLine
    If InStr(strLine, "ScomConnector") <> 0 Then
        strNewContents = strNewContents & strLine & vbCrLf
    End If
Loop
objFile.Close
thisday = Right(Year(Date),2) & Right("0" & Month(Date),2) & Right("0" & Day(Date),2)
Set objFile = objFSO.OpenTextFile(C:\ParserIIS\ex" & thisday & ".txt", 8)
objFile.Write strNewContents
objFile.Close

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Any Questions: It's possible to firstly create file date-based name and later write information to this? How it should be doing?
 
It works :D
Thanks :)

Improved code below. Maybe it helps someone :)

Set objFSO = CreateObject("Scripting.FileSystemObject")


thisday = Right(Year(Date),2) & Right("0" & Month(Date),2) & Right("0" & Day(Date),2)
Set objfile = objFSO.CreateTextFile("C:\ParserIIS\ex" & thisday & ".txt")
Set objFile = objFSO.OpenTextFile("C:\ex" & thisday & ".txt", 1)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
If InStr(strLine, "ScomConnector") <> 0 Then
strNewContents = strNewContents & strLine & vbCrLf
End If
Loop
objFile.Close
Set objFile = objFSO.OpenTextFile("C:\ParserIIS\ex" & thisday & ".txt", 8)
objFile.Write strNewContents
objFile.Close
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top