If Exist And Else in batch

2019-08-02 02:52发布

How would I add and Else option into this to say:
You don't have the java dev kit please select option 4?

FOR /R "C:\Program Files" %%a IN (.) DO (
    IF EXIST "%%~a\javac.exe" ECHO You Have The Java Dev Kit Ignore Option 4
) 

标签: batch-file
2条回答
家丑人穷心不美
2楼-- · 2019-08-02 03:11
SET found=0
FOR /R "C:\Program Files" %%a IN (.) DO (
    IF EXIST "%%~a\javac.exe" ( ECHO You Have The Java Dev Kit Ignore Option 4 
    SET found=1)
) 
IF %found%==0 ( ECHO You don't have the java dev kit please select option 4 )

If you want ELSE you must use ( and ) brackets.

查看更多
老娘就宠你
3楼-- · 2019-08-02 03:27

You need to search fist all subdirectories to decide if it's there.

set found=0
FOR /R "C:\Program Files" %%a IN (.) DO (
    IF EXIST "%%~a\javac.exe" set found=1
)
if %found%==0 (
   ECHO You don't have the java dev kit please select option 4
) ELSE (
   echo Found javac.exe
)
查看更多
登录 后发表回答