批处理文件-为什么当Folder1和2同时存在时两个goto标签都执行

时间:2018-10-26 15:25:50

标签: batch-file

对于以下批处理文件,当两个或两个文件夹都不存在时,仅执行正确的:notfound标签,但是当两个文件夹均存在时,则同时执行:bothfound:notfound标签

当文件夹Temp1和Temp2都存在时,如何仅运行:bothfound

@ECHO OFF

set "folder1=C:\Temp1\"
set "folder2=C:\Temp2\"

IF EXIST %folder1% IF EXIST %folder2% goto bothfound
goto notfound


:bothfound
echo Both folders exist.

:notfound
echo either one or both folder not exist.

echo Done.
pause

1 个答案:

答案 0 :(得分:1)

与您其他question的问题相同。

批处理文件从上到下处理。如果未使用goto跳过行,它将执行下一行。这些并不是您在现代编程语言中所想到的方法。新标签的开始并不意味着先前标签的结束。

:bothfound
echo Both folders exist.
goto end

:notfound
echo either one or both folder not exist.
goto end

:end
echo Done.
pause