set myPath="program files"
echo.%myPath: =%20%
%%20 or ^%20 doesn't work too.
It seems impossible to replace something by percent character

Moderator: DosItHelp
Code: Select all
@echo off
setlocal enabledelayedexpansion
set myPath="program files are here"
call :replace %myPath%
echo %result%
goto :eof
:::::::::::::::::::::::::::::::
:replace
::: Only to remove the "
call :replace_int %~1
goto :eof
:::::::::::::::::::::::::::::::
:replace_int
setlocal
set tmp=
:replace.loop
set tmp=!tmp!%1
if "%2"=="" goto :finish
set tmp=!tmp!%%20
shift
goto :replace.loop
:finish
(
endlocal
set result=%tmp%
goto :eof
)
Code: Select all
SETLOCAL ENABLEDELAYEDEXPANSION
set myPath=program files
echo."!myPath: =%%20!"
"program%20files"
Code: Select all
SETLOCAL ENABLEDELAYEDEXPANSION
set myPath="program files"
set myPath=!myPath: =%%20!
echo.%myPath%
"program%20files"
Code: Select all
SETLOCAL ENABLEDELAYEDEXPANSION
set myPath=program files
set myPath=!myPath: =%%20!
echo.%myPath%
program%20files