Batch file if的奇怪行为

Batch file if的奇怪行为,batch-file,cmd,Batch File,Cmd,我在这里可能很傻,但我无法理解我拥有的这段批处理代码的奇怪行为 因此,我有以下代码: @echo off set exitval=0 :selectdir echo Type the name of the folder where the software is installed (or drag and echo drop the folder here): set /p sdir= set sdir=%sdir:"=% echo. if not exist "%sdir%\Lib

我在这里可能很傻,但我无法理解我拥有的这段批处理代码的奇怪行为

因此,我有以下代码:

@echo off

set exitval=0

:selectdir
echo Type the name of the folder where the software is installed (or drag and
echo drop the folder here):

set /p sdir=
set sdir=%sdir:"=%

echo.
if not exist "%sdir%\Lib\Plugins" (
    echo The plugins directory does not exist! Try again ^(y/N^)^?
    set /p c=

    if "%c%" == "y" goto selectdir

    goto exitscript
)

:exitscript
pause
exit /b %exitval%
至少可以说,它没有表现出一致的行为:

D:\Development>test.cmd
Type the name of the folder where the software is installed (or drag and
drop the folder here):
C:\xyz

The plugins directory does not exist! Try again (y/N)?
y
Press any key to continue . . .

D:\Development>test.cmd
Type the name of the folder where the software is installed (or drag and
drop the folder here):
C:\xyz

The plugins directory does not exist! Try again (y/N)?
n
Type the name of the folder where the software is installed (or drag and
drop the folder here):
C:\xyz

The plugins directory does not exist! Try again (y/N)?
n
Press any key to continue . . .

上面的代码有什么问题?为什么它不能始终如一地工作?

我更改了缩进的行。您需要按照设置的方式延迟扩展,而这种方式不需要延迟扩展

@echo off

set exitval=0

:selectdir
echo Type the name of the folder where the software is installed (or drag and
echo drop the folder here):

set /p sdir=
set sdir=%sdir:"=%

echo.
    if exist "%sdir%\Lib\Plugins\" goto :continue
    set "c="
    set /p "c=The plugins directory does not exist! Try again (y/N)? "
    if /i "%c%" == "y" goto :selectdir
    goto :exitscript

    :continue
    echo do more stuff
    goto :eof


:exitscript
pause
exit /b %exitval%