2013-10-09 1 views
0

나는 여기에 바보가 될지 모르지만 나는이 배치 코드 조각의 이상한 동작을 파악할 수 없다.만약 이상한 동작이있는 경우

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 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% 

은 적어도 말을 :

그래서 나는 다음과 같은 코드 조각이? 왜 일관되게 작동하지 않습니까?

답변

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%