I\'m trying to make this work in a windows batch file:
if not exist \"%~n1.ext\" (
set /P z=\"PROMPT (y,n)?\"
if /i \"%z%\" == \"y\" (
Stephan is correct, you need to use enabledlayedexpansion when using a nested variable. Here's your code with that syntax (replacing %
with !
when using such variables):
setlocal enabledelayedexpansion
if not exist "%~n1.ext" (
set /P z="PROMPT (y,n)?"
if /i "!z!" == "y" (
echo if is working
)
)
When you use a variable inside a block (between (
and )
, you need to enable delayed expansion:
setlocal enabledelayedexpansion
set var=hello
if "a"=="a" (
set var=world
echo %var% !var!
)