batch file - looking for way if both folder exist then proceed else skip the operation

白昼怎懂夜的黑 提交于 2019-12-23 04:20:13

问题


I have a below batch file where if both folder1 and folder2 both exist then I want to execute else don't want to do anything.

Here even my folder NOT exist, I am getting echo message Both folders exist. What I am doing wrong here?

@ECHO OFF

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

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

:bothfound
echo Both folders exist.
goto end

:end
echo Done.
pause

回答1:


This is because you don't have a GOTO to bypass the :bothfound block. After the if exist statements, it continues on because it never invoked the goto. After you do your if exist, you need a goto end or a goto to a not found block.

example:

IF EXIST %folder1% IF EXIST %folder2% goto bothfound
goto end

:bothfound


来源:https://stackoverflow.com/questions/53009512/batch-file-looking-for-way-if-both-folder-exist-then-proceed-else-skip-the-ope

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!