I have a variable set to a value. I want to escape multiple characters in the string with a backtick (`). Here is an example of replacing occurences of a parenthesis with a backtick:
@echo off
REM SET EXAMPLE VALUE
set EXAMPLEINSTALLDIR="C:\Program Files(x86)"
echo %EXAMPLEINSTALLDIR%
REM REMOVE QUOTES
set EXAMPLEINSTALLDIR=%EXAMPLEINSTALLDIR:"=%
echo %EXAMPLEINSTALLDIR%
REM REPLACE ( WITH `(
set EXAMPLEINSTALLDIR=%EXAMPLEINSTALLDIR:(=`(%
echo %EXAMPLEINSTALLDIR%
I'd prefer to have one function to replace all specified characters (*[]+ etc). But I'm struggling. From an example found here: http://www.dostips.com/DtTutoFunctions.php
I've tried this:
set EXAMPLEINSTALLDIR="C:\Program Files(x86)\Test"
echo %EXAMPLEINSTALLDIR%
call:myGetFunc EXAMPLEINSTALLDIR %EXAMPLEINSTALLDIR%
echo %EXAMPLEINSTALLDIR%
:myGetFunc
set "%~1=%%~2:(=`(%
goto:eof
But it doesn't work. Any advice appreciated.....