“_REPLACE.EXE saves a lot of time and trouble if you want to perform the same ‘search and replace’ operation on more than one file.”
Free Download: Program for Performing a
Multiple File Global Search and Replace
By Howard Best, October 19, 2001
(_REPLACE.EXE Updated: June 4, 2004)
(llbest.com, hbest@hotmail.com)
_REPLACE.EXE (Download now) works with
all versions of Windows, including Windows XP.
It works like a DOS command, so it may be executed from the DOS command line. It may also be executed from Windows by placing it’s command syntax within a “.bat” file.
_REPLACE.EXE saves a lot of time and trouble if you want to perform the same “search and replace” operation on more than one file. Multiple multi-file search and replace operations may be performed by creating a .bat file containing multiple _REPLACE commands.
One thing that I really like about this program is that, unlike similar programs, it does not change the time/date stamp of files which it doesn’t change. This makes it very easy to separate the modified files by sorting by “Date Modified”.
Here is what you get if you type “_replace /?” on the DOS command line or if you double click the “_REPLACE.EXE” icon (using Windows):
Note: If any of the following lines are cut off on the right, use IE’s “View/Text Size” to make the text smaller.
Does a "multiple file global search and replace". (Does a search and replace operation on all of the .TXT files in a particular folder.) _REPLACE "search string" ["replacement string"] [/I] [/S] [/T] [/MIN=n] [/MAX=n] [/EXT=s] /I Ignore case. /S Include subdirectories. /T Test mode (Do not make any actual changes to any files). /MIN=n Minimum allowable replacements per file (Default = 0). /MAX=n Maximum allowable replacements per file (Default = 99999). /EXT=s Perform operations only on files with extension s (Default = .txt). If "replacement string" is omitted, a null replacement string is used. 6 types of search/replacement string characters have special representations: Backslash (\) - "\b" or "\B" New line - "\n" or "\N" Percent sign (%) - "\p" or "\P" Quote sign (") - "\q" or "\Q" Tab - "\t" or "\T" Decimal code - "\ddd" where ddd is a 3 digit number between 001 & 255. Press any key to continue . . . |
NOTE: Using the /MIN= and /MAX= switches causes the possibility of diagnostic error messages to be displayed. They have no effect on the outcome of the search and replace operations.
EXAMPLE #1: Suppose that you want to update a folder full of “.htm” files, some of which may be missing the > character on the end of the </html>. You also want to check to make sure that each .htm file has one and only one </html>. The following is a “.bat” file designed to do the job:
_replace "</html" "</html>" /min=1 /max=1 /ext=.htm /i _replace "</html>>" "</html>" /min=1 /max=1 /ext=.htm /i pause |
EXAMPLE #2: Suppose that you want to test “.html” files to see if the number of <i> strings is equal to the number of </i> strings, but you don’t want to actually make any changes to the files or to update any of the files’ “Date Modified” time/date stamps. The following is the required .bat file:
_replace "<i>" "<i>" /max=0 /ext=.html /i /t _replace "</i>" "</i>" /max=0 /ext=.html /i /t pause |
EXAMPLE #3: Suppose that you have a folder containing more than 100 .htm files, each one containing the string: http://yourwebsite.com/..., and you want to change each of the ... strings to the file name of that particular .htm file. Using this web page as an example, http://llbest.com/... should be changed to http://llbest.com/_REPLACE.htm. Here’s a .bat file which will execute “_replace.exe” 100+ times in order to perform each of the unique file edits:
for %%x in (*.htm) do _replace ".com/..." ".com/%%x" /ext=%%x pause |
NOTE: /ext= can also be followed by an entire file name (%%x) instead of just a file name extension.
Suggestions for improvements would be very much appreciated.
Howard Best (hbest@hotmail.com)
THIS WEB PAGE URL: http://llbest.com/_REPLACE.htm