replacer.exe
replacer.exe
simply replaces a given string for another given string in a given file. The file is overwritten by the new derivate.
replacer.exe
is written in C#, namely, this line:
File.WriteAllText (args[0], File.ReadAllText (args[0]).Replace (args[1], args[2]));
(Warning: make sure the program has not been upgraded by the time you are reading this.)
We use replacer.exe
for upgrading project files and Web.config
after copying new assemblies to our PhoneBook
project.
Usage
In the C:\PhoneBook-SVN\tools
subdirectory (or wherever), incant this:
replacer\replacer\bin\Debug\replacer.exe C:\PhoneBook-SVN\PhoneBook.Web\Web.config 1.13.6.2 1.13.13.2
This will overwrite the Web.config
file with a new derivative, containing no more "1.13.6.2" strings, because they were all replaced by "1.13.13.2".
We have prepared a file in the dummy
sub-directory for you to play with:
C:\PhoneBook-SVN\tools>type dummy\replacer-test.txt On today's menu we have Spam, Spam, Spam, Spam, Spam, baked beans, Spam, Spam, Spam and Spam. C:\PhoneBook-SVN\tools>replacer\replacer\bin\debug\replacer.exe dummy\replacer-test.txt Spam HAM C:\PhoneBook-SVN\tools>type dummy\replacer-test.txt On today's menu we have HAM, HAM, HAM, HAM, HAM, baked beans, HAM, HAM, HAM and HAM. REM BE A GOOD CITIZEN, RESTORE THE ORIGINAL TEST FILE C:\PhoneBook-SVN\tools>copy dummy\replacer-test-orig.txt dummy\replacer-test.txt Overwrite dummy\replacer-test.txt? (Yes/No/All): y 1 file(s) copied.
Room for improvement
replacer.exe
should report an error if no strings can be found for substitution