can any one please post a vbscript to append the content to a specific line (Say line 5) of a text and also vbscript for deleting the content
Thanks in advance.
0 Comments   [ - ] Hide Comments


Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
Answer this question or Comment on this question for clarity


Read the text file lines one by one. When you get the string which you are searching for, add your string to it. Store this in another string and write back to the text file.

Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists("<PATH TO YOUR FILE>") then
Set objFile = objFSO.OpenTextFile("<PATH TO YOUR FILE>", 1)

Do Until objFile.AtEndOfStream
strLine = objTextFile.Readline
If strNextLine = "LINE YOU ARE LOOKING FOR" then
strLine = strLine + " ADD YOUR STRING HERE"
End If

strNewText = strLine + vbcrlf
Set objFile = Nothing

Set objFile = objFSO.OpenTextFile("<PATH TO YOUR FILE>", 2)
objFile.Write strNewText
Set objFile = Nothing
End If
Answered 11/22/2010 by: murali.bhat
Purple Belt

Please log in to comment
It's much more efficient to use ReadAll, then Split using vbCRLF as the delimiter to create an array, then loop through the array.

For deleting a line, you simply hop over it in the testing loop.

BTW, if - as I suspect - you're appending to the HOSTS or SERVICES file, remember to test whether or not the data you're adding is already present.
Answered 11/23/2010 by: VBScab
Red Belt

Please log in to comment