I have made a batch script that replaces strings in a specified text-based file. Within my file, the string OutDir=bin
should be replaced as OutDir=Build
but gets output as bin=OutDir=Build=bin
. How do I escape the =
in OutDir=bin
so that the string doesn't become garbled? I have tried OutDir^=
but using the carrot doesn't work either.
Here is my current script:
@echo off setlocal enableextensions disabledelayedexpansion set search=OutDir=bin set replace=OutDir=Build set textFile=%DOCUMENT%.txt for /f "delims=" %%i in ('type "%textFile%" ^& break ^> "%textFile%"') do ( set "line=%%i" setlocal enabledelayedexpansion>>"%textFile%" echo(!line:%search%=%replace%! endlocal )
I have attempted to change the find and replace variables to compensate for the =
in the string I'm replacing but none have worked:
set search= "OutDir=bin"set replace= "OutDir=Build"set search="OutDir=bin"set replace="OutDir=Build"set "search=OutDir=bin"set "replace=OutDir=Build""set search=OutDir=bin""set replace=OutDir=Build"