批处理文件-寻找同时存在两个文件夹的方式,然后继续进行操作,否则跳过该操作 [英] batch file - looking for way if both folder exist then proceed else skip the operation

查看:100
本文介绍了批处理文件-寻找同时存在两个文件夹的方式,然后继续进行操作,否则跳过该操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个下面的批处理文件,如果folder1和folder2都存在,那么我要执行,否则什么也不想做.

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.

这里甚至我的文件夹都不存在,我收到了echo消息Both folders exist.我在这里做错了什么?

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

推荐答案

这是因为您没有GOTO来绕过:bothfound块.在if exist语句之后,它继续进行,因为它从未调用goto.如果存在,则需要转到末尾或转到未找到的块.

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.

示例:

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

:bothfound

这篇关于批处理文件-寻找同时存在两个文件夹的方式,然后继续进行操作,否则跳过该操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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