I am trying to replace text in a file repeatedly. However, once I replace the text once, it gets replaced again.
I am using a .vbs file that replaces text, and a .bat file that executes the .vbs file repeatedly. I am trying to execute it in such a way that after text is replaced, it is not replaced again.
I have one .vbs file called replace.vbs that I got from this link:
How can you find and replace text in a file using the Windows command-line environment?
Const ForReading = 1
Const ForWriting = 2
strFileName = Wscript.Arguments(0)
strOldText = Wscript.Arguments(1)
strNewText = Wscript.Arguments(2)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFileName, ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, strOldText, strNewText)
Set objFile = objFSO.OpenTextFile(strFileName, ForWriting)
objFile.Write strNewText 'WriteLine adds extra CR/LF
objFile.Close
And I have a .bat file that executes replace.vbs repeatedly (the full script runs replace.vbs 56 times)
SET abcpath=C:\test\myFile.txt
cscript replace.vbs %abcpath% "Hello World" "Testing"
cscript replace.vbs %abcpath% "Testing" "Text"
PAUSE
The text in myFile.txt is "Hello World Testing" the intended output is "Testing Text" however the output is "Text Text". How can I have the second time replace.vbs is executed ignore all text that was replaced during the first time it was executed?
It is possible that There is a simpler solution that is evading me, so I will back up a step. What I am actually trying to do is take a text file that has the letters a to g (upper and lowercase) followed by up to 3 apostrophes or up to 4 commas (at no point does it have commas and apostrophes). there are 52 combinations and I am trying to map each possible combination to one letter (52 different letters because its case sensitive)