Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Updating a TXT File.... HELP

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,60199
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Updating a TXT File.... HELP
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Updating a TXT File.... HELP - 5/14/2008 5:39:27 AM   
  jpook

 

Posts: 30
Score: 0
Joined: 3/7/2007
Status: offline
Okay.. i've been looking around and I'm not sure how to do this...

What I'm trying to do:
   - is open a txt file (example of file below) and run a ping script on the hostname, and then have the script write back over the same text file (same record) and change the time.

Text File Example:
----------------------------------------
Hostname,notes,time
Hostname,notes,time
Hostname,notes,time
Hostname,notes,time


This is how I loop & break up the text file.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

'spit Txt file -------------------------------------------------------------
Dim fs3,objTextFile
Set fs3=CreateObject("Scripting.FileSystemObject")
Dim arrStr
Set objTextFile = fs3.OpenTextFile("File.txt")
Do While Not objTextFile.AtEndOfStream
arrStr = split(objTextFile.ReadLine,",")

' Code Here '

loop

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 
 
Post #: 1
 
 RE: Updating a TXT File.... HELP - 5/14/2008 5:46:59 AM   
  ebgreen


Posts: 4971
Score: 31
Joined: 7/12/2005
Status: offline
What are you asking for help with? How to ping? How to get the result of the ping? How to write the result to the file? Please show all the code that you have so far.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to jpook)
 
 
Post #: 2
 
 RE: Updating a TXT File.... HELP - 5/14/2008 6:12:25 AM   
  jpook

 

Posts: 30
Score: 0
Joined: 3/7/2007
Status: offline
** I was looking for help with writing back to the TXT file. I updating a HTML page, and want the 'Time' of the last good ping to update in the TXT file after each round.



'==========================================================================
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists("FILE.txt") Then
   Set objFolder = objFSO.GetFile("File.txt")
Else
   Wscript.Echo " File.txt File does not exist."
   ' Write Error in Log
   WScript.Quit 'Exit entire script
End If
Const ForRead = 1, ForWrite = 2, ForAppend = 8

Set fs2 = CreateObject("Scripting.FileSystemObject")
If fs2.FileExists("index.txt") Then
Set openFileindex  = fs2.OpenTextFile("index.txt", ForWrite)
Else
Dim fso2
Set fso2 = CreateObject("Scripting.FileSystemObject")
Set openFileindex  = fso2.CreateTextFile("index.txt", ForWrite)

End If
'-------------
openfileindex.WriteLine


Dim fs3,objTextFile
Set fs3=CreateObject("Scripting.FileSystemObject")
Dim arrStr
Set objTextFile = fs3.OpenTextFile("File.txt")
Do While Not objTextFile.AtEndOfStream
arrStr = split(objTextFile.ReadLine,",")

If IsAlive( arrStr(0) ) Then
Icon = (" <img border='0' src='green.jpg' width='18' height='22'> ")
indextime = Now
openFileindex.WriteLine ("<table border='0' width='100%' id='table2222'><tr><td width='242' align='center'><font color='#00FF00'>") & arrStr(0) & ("</font></td><td width='306' align='center'><font color='#00FF00'>") & indextime & ("</font></td><td width='293' align='center'><font color='#00FF00'>") & arrStr(1) & ("</font></td><td align='center'>") & icon & ("</td></tr></table>")
Else
Icon = (" <img border='0' src='red.jpg' width='18' height='22'> ")
openFileindex.WriteLine ("<table border='0' width='100%' id='table2222'><tr><td width='242' align='center'><font color='#00FF00'>") & arrStr(0) & ("</font></td><td width='306' align='center'><font color='#00FF00'>10/25/56 15465:545</font></td><td width='293' align='center'><font color='#00FF00'>") & arrStr(1) & ("</font></td><td align='center'>") & icon & ("</td></tr></table>")


End If


'--------------------
' Need code to update txt file.. Just the 'time' Part

Text File Example:
----------------------------------------
Hostname,notes,time
Hostname,notes,time
Hostname,notes,time
Hostname,notes,time


Loop


Function IsAlive(strHost)

   Const OpenAsASCII = 0
    Const FailIfNotExist = 0
    Const ForReading =  1
    Dim objShell, objFSO, sTempFile, fFile
   Set objShell = CreateObject("WScript.Shell")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
   sTempFile = objFSO.GetSpecialFolder(2).ShortPath & "\" & objFSO.GetTempName
   objShell.Run "%comspec% /c ping.exe -n 2 -w 500 " & strHost & ">" & sTempFile, 0 , True
   Set fFile = objFSO.OpenTextFile(sTempFile, ForReading, FailIfNotExist, OpenAsASCII)
   Select Case InStr(fFile.ReadAll, "TTL=")
        Case 0
           IsAlive = False
        Case Else
           IsAlive = True
   End Select
   fFile.Close
    objFSO.DeleteFile(sTempFile)
   Set objFSO = Nothing
   Set objShell = Nothing
End Function

(in reply to jpook)
 
 
Post #: 3
 
 RE: Updating a TXT File.... HELP - 5/14/2008 6:16:56 AM   
  ebgreen


Posts: 4971
Score: 31
Joined: 7/12/2005
Status: offline
Ok, just build up a string as you go along that is the new contents of the file. Then when you have gone all the way throught the file (after the loop), close the file. Then open the file ForWriting and write the string to it. Then close the file.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to jpook)
 
 
Post #: 4
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Updating a TXT File.... HELP Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts