为什么这个简单的批处理脚本不起作用?

时间:2014-02-25 18:54:31

标签: batch-file switch-statement

尝试使用.dll是否使用简单的开关BATCH。这是代码:它似乎什么都不做,但我找不到任何错误。 HELP?

:StartProgram
@echo off

set /p UsePowerup= Would you like to use power up plug in (1=Yes;2=No;3=Exit)?

If %UsePowerup%=3 
(
    EXIT
)
Else IF %UsePowerup%=2
(
    CD C:\Program Files (x86)\Steam\SteamApps\common\Fallout New Vegas\Data\NVSE\Plugins\

    If EXIST geckpu-nv-14.dll
    (
        ECHO "Moving Power Up Plugin to Desktop"
        MOVE geckpu-nv-14.dll C:\Users\Anonymous\Desktop\
        ECHO "Move Power Up Plugin to Desktop SUCCESS"
        PAUSE
        GOTO RunGECK
    )
    Else
    (
        ECHO "Plug-in not found! Try again."
        PAUSE
        GOTO StartProgram
    )
)
Else IF %UsePowerup%=1
(

    cd C:\Users\Anonymous\Desktop\
    If EXIST geckpu-nv-14.dll
    (
        ECHO "Moving Power Up Plugin to GECK"
        MOVE geckpu-nv-14.dll C:\Program Files (x86)\Steam\SteamApps\common\Fallout New Vegas\Data\NVSE\Plugins\
        ECHO "Move Power Up Plugin to Desktop SUCCESS"
        PAUSE
        GOTO RunGECK
    )
    Else
    ( 
        ECHO "Plug-in not found! Try again."
        PAUSE
        GOTO StartProgram
    )
)
Else ECHO "INVALID CHOICE Try Again"
(
    PAUSE
    CLS
    GOTO StartProgram
)


:RunGECK

cd C:\Program Files (x86)\Steam\SteamApps\common\Fallout New Vegas\
nvse_loader -editor
exit

谢谢你们

1 个答案:

答案 0 :(得分:1)

您的IF语句的括号必须在同一行。这同样适用于ELSE语句。您必须使用==或EQU进行比较。您需要在CD命令中添加/ d直接转到路径,并且需要引用带有空格的路径。您需要在函数之前的脚本末尾添加exit / b或goto:eof,否则函数将始终在没有参数的情况下运行。

我认为这应该让你更接近。

@echo off
:StartProgram
set /p UsePowerup=Would you like to use power up plug in (1=Yes;2=No;3=Exit)? 

If %UsePowerup%==3 (
    EXIT
) Else (
    IF %UsePowerup%==2(
      CD /d "C:\Program Files (x86)\Steam\SteamApps\common\Fallout New Vegas\Data\NVSE\Plugins\"

        If EXIST geckpu-nv-14.dll (
            ECHO "Moving Power Up Plugin to Desktop"
            MOVE geckpu-nv-14.dll "C:\Users\Anonymous\Desktop\"
            ECHO "Move Power Up Plugin to Desktop SUCCESS"
            PAUSE
            GOTO RunGECK
        ) Else (
            ECHO "Plug-in not found! Try again."
            PAUSE
            GOTO StartProgram
        )
    ) Else (
        IF %UsePowerup%==1(

            cd /d "C:\Users\Anonymous\Desktop\"
            If EXIST geckpu-nv-14.dll (
                ECHO "Moving Power Up Plugin to GECK"
                MOVE geckpu-nv-14.dll "C:\Program Files (x86)\Steam\SteamApps\common\Fallout New Vegas\Data\NVSE\Plugins\"
                ECHO "Move Power Up Plugin to Desktop SUCCESS"
                PAUSE
                GOTO RunGECK
            ) Else ( 
                ECHO "Plug-in not found! Try again."
                PAUSE
                GOTO StartProgram
            )
        ) Else ( 
            ECHO "INVALID CHOICE Try Again"
            PAUSE
            CLS
            GOTO StartProgram
        )
    )
)   
exit /b

:RunGECK
cd /d "C:\Program Files (x86)\Steam\SteamApps\common\Fallout New Vegas\"
nvse_loader -editor
exit