I am trying to write a script that reads a txt file, searches for branch=xxx (xxx= any 3 digit number) and replaces the line with branch=yyy) yyy=input variable.
the script below appends yyy onto xxx rather than replace - any ideas.
Test.123 is a text file that contains the text BRANCH=123
Const ForReading = 1
printer = inputbox("Enter Branch number - eg. B123")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\TEST.123", ForReading)
strContents = objFile.ReadAll
objFile.Close
Const ForWriting = 2
StrNewContents = Replace(strContents,"BRANCH=" + (MID(8 ,10)),"BRANCH=" + printer)
Set objFile = objFSO.OpenTextFile("C:\Test.123", ForWriting)
objFile.WriteLine strNewContents
wscript.echo strnewcontents
objFile.Close
the script below appends yyy onto xxx rather than replace - any ideas.
Test.123 is a text file that contains the text BRANCH=123
Const ForReading = 1
printer = inputbox("Enter Branch number - eg. B123")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\TEST.123", ForReading)
strContents = objFile.ReadAll
objFile.Close
Const ForWriting = 2
StrNewContents = Replace(strContents,"BRANCH=" + (MID(8 ,10)),"BRANCH=" + printer)
Set objFile = objFSO.OpenTextFile("C:\Test.123", ForWriting)
objFile.WriteLine strNewContents
wscript.echo strnewcontents
objFile.Close