1.

Solve : Batch file : replacing text part in files with FOR command?

Answer»

Hello,

I have a TexRep software from No Nonsense Software. I can make my changes singly.
I'ld like to make my changes automatically. It means, there are several .htm files in a folder and NEED to change TEXT PARTS in this files. How can I do it with FOR command in a batch file?
e.g:
texrep *.htm "texttofind" "replacewith"

Sorry if it is an resolved issue but I couldn't find.
Thanks,
CsabaText files cannot be updated in place with batch code. This little snippet produces output files with a chg extension.

Code: [Select]@echo off
setlocal enabledelayedexpansion

set /p search=Search String=
set /p replace=Replace With=

for %%v in (*.htm) do (
for /f "tokens=*" %%a in (%%v) do (
set newline=%%a
set newline=!newline:%search%=%replace%!
echo !newline! >> %%~nv.chg
)
)

If not run from the htm directory, you may have to add paths to the code.

Good luck. Quote from: Sidewinder

Text files cannot be updated in place with batch code.

You can PRODUCE a new file which contains the CHANGED text, delete the original file, then rename the new file with the original name.


Discussion

No Comment Found