Darkejo1
asked on
Replace specified text in text file with nothing in .vbs.
What i'm trying to do is search through a .txt file and replace a specified line or delete it using .vbs. I know I need to open the file, read it to memory, then write the info into another file. Can someone show me how to do this?
No points for this! :)
Change:
Set objFile = objFSO.CreateTextFile(File Name)
to:
Set objFile = objFSO.CreateTextFile(File Name, True)
Change:
Set objFile = objFSO.CreateTextFile(File
to:
Set objFile = objFSO.CreateTextFile(File
I'm not 100% certain that's necessary? If it's a 'just in case' - then I probably agree with you, but if the file is closed, I've not had a problem overwriting it before...
ASKER
It wasn't needed. However it's not working. It tell sme "object Required". The data is in the text file. What does this mean?
strcomputer1 = Trim(strcomputer)
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
OriginalText = "10.144.39.100"
FileName = "C:\computerlist.txt"
Set objFile= objFSO.OpenTextFile(FileName).ReadAll
newData = Replace(objFile.ReadAll, OriginalText, "")
objFile.Close
Set objFile = objFSO.CreateTextFile(FileName)
objFile.Write newData
objFile.Close
untitled.bmp
Um - then something else is added here? THere's only 12 lines in this script your error references line 98?
You running this in an HTA?
You running this in an HTA?
ASKER
Yes, This is only part of a larger peice of the puzzle. I've removed the rest and kept only your code. I still get the error message.
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
OriginalText = "10.144.39.100"
FileName = "C:\computerlist.txt"
Set objFile= objFSO.OpenTextFile(FileName).ReadAll
newData = Replace(objFile.ReadAll, OriginalText, "")
objFile.Close
Set objFile = objFSO.CreateTextFile(FileName)
objFile.Write newData
objFile.Close
untitled.bmp
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That did the trick! Thank you!
Open in new window