1

似乎每当我运行我的批处理文件时,一切都会运行,它会进入checkfiles,但它不运行 if 语句。没有返回任何内容,它只是直接跳到代码的最后一部分。

:file_check
if exist "%psychedelia%\nhc.exe" (goto file_exists) else (timeout /t 1 /nobreak > output)
goto file_check

:file_exists
copy /Y "%~dp0version.txt" "%psychedelia%"

:checkfiles
echo in checkfiles
if exist "%psychedelia%\wa.exe" if exist "%psychedelia%\readme.txt" if exist "%psychedelia%\HD.BLB" if exist "%psychedelia%\smackw32.dll" if exist "%psychedelia%\setup95.exe" if exist "%psychedelia%\WAVistaWin7.exe" (
    echo MSGBOX "Thank you for installing the Neverhood. You may now go to your desktop and click on the Orpheus shortcut to play!" > %temp%\TEMPxmessage.vbs
    call %temp%\TEMPxmessage.vbs
    del %temp%\TEMPxmessage.vbs /f /q
    rename "%psychedelia%\nhc.exe" wa.exe
    timeout /t 1 /nobreak > output
    taskkill.exe /F /IM setup95.exe /T
) else ( 
    echo nonexistent
    pause
    timeout /t 1 /nobreak > output
    goto checkfiles
)

非常感谢所有帮助。

4

2 回答 2

4

只有该if exist行的最后一个有括号,所以elseonly 适用于最后一个。如果第一个评估为假,它将跳过整个事情。

于 2013-03-23T03:50:06.500 回答
1

尝试:

...
echo in checkfiles
for %%f in (wa.exe 
            readme.txt 
            HD.BLB 
            smackw32.dll 
            setup95.exe 
            WAVistaWin7.exe
           ) do if not exist "%psychedelia%\%%f" (
    echo %%f nonexistent
    pause
    timeout /t 1 /nobreak > output
    goto checkfiles
   )

:: all required files found

echo MSGBOX "Thank you for installing the Neverhood. You may now go to your desktop and click on the Orpheus shortcut to play!" > %temp%\TEMPxmessage.vbs
call %temp%\TEMPxmessage.vbs
del %temp%\TEMPxmessage.vbs /f /q
rename "%psychedelia%\nhc.exe" wa.exe
timeout /t 1 /nobreak > output
taskkill.exe /F /IM setup95.exe /T

它可能更容易维护。

事实上,你甚至可以写

set requiredfiles=wa.exe readme.txt HD.BLB smackw32.dll setup95.exe WAVistaWin7.exe
for %%f in (%requiredfiles%) do if not exist "%psychedelia%\%%f" (
...

这会更容易。

但请接受Nate Hekman的回答 - 这只是一个顺便说一句*

于 2013-03-23T05:34:37.550 回答