批处理文件-为什么在folder1和amp; amp;都同时执行两个goto标签2存在 [英] batch file - why both goto labels executes when both folder1 & 2 exist

查看:77
本文介绍了批处理文件-为什么在folder1和amp; amp;都同时执行两个goto标签2存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

For below batch file, When both or any one folder NOT exist then ONLY :notfound label execute which is correct, but when both folder exist, then both :bothfound and :notfound labels execute.

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

How we can run ONLY execute :bothfound when both folder Temp1 and Temp2 exist?

@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

推荐答案

与您的其他

Same problem as your other question.

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

Batch files process top to bottom. If a goto is not employed to skip lines, it will execute the next line. These are not methods like you think of in a modern programming language; the start of a new label doe not imply an end to the prior label.

:bothfound
echo Both folders exist.
goto end

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

:end
echo Done.
pause

这篇关于批处理文件-为什么在folder1和amp; amp;都同时执行两个goto标签2存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆