0

我可能在这里很愚蠢,但我根本无法弄清楚我拥有的这段批处理代码的奇怪行为。

所以我有以下代码:

@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 . . .

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

4

1 回答 1

2

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

@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%
于 2013-10-09T12:40:29.947 回答