how to change word in text file by VB script (like sed in unix)
A:
Following steps: (when tackling a computing problem, divide and conquer!)
- Open the text file
- Save file contents to string variables
- Close the text file!
- Search variable for the word
- Replace the word(s)
- Save the variable as a text file overwriting old one
With the help of Google, you should be able to search and discover how to achieve all of the above points.
Tom Gullen
2010-06-16 16:02:23
+1
A:
You can use the FileSystemObject Object. Some notes:
Set fs = CreateObject("Scripting.FileSystemObject")
sf = "C:\Docs\In.txt"
Set f = fs.OpenTextFile(sf, 1) ''1=for reading
s = f.ReadAll
s = Replace(s, "Bird", "Cat")
f.Close
Set f = fs.OpenTextFile(sf, 2) ''2=ForWriting
f.Write s
f.Close
Remou
2010-06-16 16:49:05