批处理文件中嵌套if-else条件的问题

Question of nested if-else condition in batch file

我不知道为什么当嵌套 if-else 从 “未找到备忘录文件和其他文件”“备忘录”时它不起作用找不到文件.

谁能帮帮我?

如能解决,不胜感激。 谢谢!

原码

@ECHO OFF
SET FOLDER="D:\temp\test"
SET TRANS="D:\temp\test\Trans\Trans.txt"
SET MEMO="D:\temp\test\Memo\Memo.txt"
SET OTHER="D:\temp\test\Other\Other.txt"

IF NOT EXIST %FOLDER% (
    ECHO Folder Not Found
) ELSE (
    IF NOT EXIST %MEMO% (
        IF NOT EXIST %TRANS% (
            IF NOT EXIST %OTHER% (
                ECHO All Files Not Found
            ) ELSE (
                IF NOT EXIST %MEMO% (
                    IF NOT EXIST %TRANS% (
                        ECHO Memo File AND Trans File Not Found
                    ) ELSE (
                        IF NOT EXIST %MEMO% (
                            IF NOT EXIST %OTHER% (
                                ECHO Memo File AND Other File Not Found
                            ) ELSE (
                                IF NOT EXIST %TRANS% (
                                    IF NOT EXIST %OTHER% (
                                        ECHO Trans File AND Other File Not Found
                                    ) ELSE (
                                        IF NOT EXIST %TRANS% (
                                            ECHO Trans File Not Found
                                        ) ELSE (
                                            IF NOT EXIST %MEMO% (
                                                ECHO Memo File Not Found
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    )
)

此示例是否输出了您要检索的信息:

@ECHO OFF
SET "FOLDER=D:\temp\test"
SET "TRANS=%FOLDER%\Trans\Trans.txt"
SET "MEMO=%FOLDER%\Memo\Memo.txt"
SET "OTHER=%FOLDER%\Other\Other.txt"

IF NOT EXIST "%FOLDER%\*" (
    ECHO Folder Not Found
) ELSE (
    IF NOT EXIST "%MEMO%" (
        IF NOT EXIST "%TRANS%" (
            IF NOT EXIST "%OTHER%" (
                ECHO All Files Not Found
            ) ELSE (
                ECHO Memo File AND Trans File Not Found
            )
        ) ELSE (
            IF NOT EXIST "%OTHER%" (
                ECHO Memo File AND Other File Not Found
            ) ELSE (
                ECHO Memo File Not Found
            )
        )
    ) ELSE (
        IF NOT EXIST "%TRANS%" (
            IF NOT EXIST "%OTHER%" (
                ECHO Trans File AND Other File Not Found
            ) ELSE (
                ECHO Trans File Not Found
            )
        ) ELSE (
            IF NOT EXIST "%OTHER%" (
                ECHO Other File Not Found
            ) ELSE (
                ECHO All Files Found
            )
        )
    )
)
PAUSE

我会这样做:

@ECHO OFF
SET FOLDER="D:\temp\test"
SET TRANS="D:\temp\test\Trans\Trans.txt"
SET MEMO="D:\temp\test\Memo\Memo.txt"
SET OTHER="D:\temp\test\Other\Other.txt"

IF NOT EXIST %FOLDER% (
    ECHO Folder Not Found
    GOTO :EOF
)

SET "NOTFOUND="
IF NOT EXIST %TRANS% SET "NOTFOUND=Trans"
IF NOT EXIST %MEMO% SET "NOTFOUND=Memo %NOTFOUND%"
IF NOT EXIST %OTHER% SET "NOTFOUND=Other %NOTFOUND%"

IF DEFINED NOTFOUND ECHO These files not found: %NOTFOUND%