Mark121
01-22-2008, 01:43 AM
Hi I am attempting to write a VB script to find and replace certian values in a file.
The only problem that it overwrite the previous find and replace....
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\file.txt", ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText,"OldValue1","NewValue1")
Set objFile = objFSO.OpenTextFile("C:\mappings.txt", ForWriting)
objFile.WriteLine strNewText
objFile.Close
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\mappings.txt", ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText,"OldValue1","NewValue1")
Set objFile = objFSO.OpenTextFile("C:\mappings.txt", ForWriting)
objFile.WriteLine strNewText
objFile.Close
Any help would be much appreciated
Regards
Mark
The only problem that it overwrite the previous find and replace....
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\file.txt", ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText,"OldValue1","NewValue1")
Set objFile = objFSO.OpenTextFile("C:\mappings.txt", ForWriting)
objFile.WriteLine strNewText
objFile.Close
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\mappings.txt", ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText,"OldValue1","NewValue1")
Set objFile = objFSO.OpenTextFile("C:\mappings.txt", ForWriting)
objFile.WriteLine strNewText
objFile.Close
Any help would be much appreciated
Regards
Mark