问题
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