If syntax in windows batch

前端 未结 2 1587
自闭症患者
自闭症患者 2021-01-26 10:22

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\" (
                   


        
2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-26 10:50

    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!
    )
    

提交回复
热议问题