Hi All
I have set of bat files. all bat file contain 'TEST_2011' text. I want to replace TEST_2011 with TEST_2012. My bat files names are r1.bat,r2.bat,r3.bat and r4.bat. Thing is I want to replace new text in all bat files at once. I tried following bat file to replace new text into bat files. But Still I can replace only in r1.bat. I expect replace new text into all bat files which are r1.bat,r2.bat,r3.bat and r4.bat. Please advise me how to fulfill my requirement.
@echo off >newr1.bat & setLocal enableDELAYedexpansion
set /p old=old string ?
set /p new=new string ?
for /f "tokens=* delims= " %%a in (r1.bat) do (
set str=%%a
set str=!str:%old%=%new%!
>> newr1.bat echo !str!
)
Thank you
Replace text in bat files
Moderator: DosItHelp
Re: Replace text in bat files
Try something like that:
Regards
aGerman
Code: Select all
@echo off &setLocal enableDelayedExpansion
set /p "old=old string ? "
set /p "new=new string ? "
for %%a in (r1.bat r2.bat r3.bat r4.bat) do (
>new%%a type nul
for /f "tokens=* delims=" %%b in (%%a) do (
set "str=%%b"
>>new%%a echo !str:%old%=%new%!
)
)
Regards
aGerman
Re: Replace text in bat files
Hi aGerman
I tried your code. It works. Many thanks
I tried your code. It works. Many thanks