Here is my Hybrid Batch/VBScript that I mentioned in my comment
Copy the code and save as FindAndReplace.cmd
Call it from a CMD
prompt or as a command in GP like this:
FindAndReplace "String to Find" "String to Replace"
The way I have it setup, it will only search for files ending in .txt and will recurse into subfolders. set the mask variable to the top level folder and filemask. If you don't want to replace text in files in subfolders, remove the /S
from the DIR
command. It isn't case sensitive so
FindAndReplace "String to Find" "String to Replace" is the same as
FindAndReplace "STRING TO FIND" "STRING TO REPLACE" or
FindAndReplace "String TO FIND" "STRING To Replace"
::Find and Replace
::Matt Williamson
::5/30/2013
@echo off
setlocal
set mask=%appdata%\My Folder\*.txt
set tmp="%temp%\tmp.txt"
If not exist %temp%\_.vbs call :MakeReplace
for /f "tokens=*" %%a in ('dir "%mask%" /s /b /a-d /on') do (
for /f "usebackq" %%b in (`Findstr /mic:"%~1" "%%a"`) do (
echo(&Echo Replacing "%~1" with "%~2" in file %%~nxa
<%%a cscript //nologo %temp%\_.vbs "%~1" "%~2">%tmp%
if exist %tmp% move /Y %tmp% "%%~dpnxa">nul
)
)
del %temp%\_.vbs
exit /b
:MakeReplace
>%temp%\_.vbs echo with Wscript
>>%temp%\_.vbs echo set args=.arguments
>>%temp%\_.vbs echo .StdOut.Write _
>>%temp%\_.vbs echo Replace(.StdIn.ReadAll,args(0),args(1),1,-1,1)
>>%temp%\_.vbs echo end with