多"如果"在批处理文件语句 [英] Multiple "If" statements in a batch file

查看:135
本文介绍了多"如果"在批处理文件语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个批处理程序,但我不知道这样的事情的命令:

I was making a batch program but i do not know the command for something like this:

IF EXIST "folder_a" AND IF EXIST "folder_b" AND IF EXIST "folder_c" THEN DO
(
    Some Code
)

请注意,这是不正确的语法/正确的程序指令。

Note that was not correct syntax/correct program commands.

如果有人知道的命令,请帮助。

If anyone knows the command please help.

推荐答案

您在你的code几个小错误。请注意,在批处理文件:

You have several small errors in your code. Note that in Batch files:


  • 如果命令不使用然后字。

  • DO 命令的一部分,而不是如果

  • 在一个如果,您必须将所需的命令的在同一行的的如果。如果要插入圆括号括起来的几个命令,开幕括号必须放置在同一行的如果

  • IF command does NOT use THEN word.
  • DO word is a part of FOR command, not IF.
  • In an IF, you must put the desired command in the same line of the IF. If you want to insert several commands enclosed in parentheses, the opening parentheses must be placed in the same line of the IF.

这是一例的有效IF:

IF EXIST "folder_a" (
    Some Code
)

如果命令你可能只满足条件之前使用,但没有办法相结合的两个条件的与AND,OR,等等。然而,您可以嵌套另一个如果命令进入第一个:

In an IF command you may only use NOT before the condition, but there is no way to combine two conditions with AND, OR, etc. However, you may nest another IF command into the first one:

IF EXIST "folder_a" IF EXIST "folder_b" IF EXIST "folder_c" (
    Some Code
)

不过,你的可能的写$与一个小窍门的援助略微清晰的方式p $ pvious code:

However, you may write previous code in a slightly clearer way with the aid of a small trick:

SET AND=IF
IF EXIST "folder_a" %AND% EXIST "folder_b" %AND% EXIST "folder_c" (
    Some Code
)

注意:你必须知道,previous线暗示的三个单独如果命令!这意味着,因为它属于只是你不能使用 ELSE 部分的最后的IF:

NOTE: You must be aware that previous line imply three individual IF commands! This means that you can NOT use ELSE part because it belongs just to the last IF:

SET AND=IF
IF EXIST "folder_a" %AND% EXIST "folder_b" %AND% EXIST "folder_c" (
    ECHO The three folders exists
) ELSE (
    ECHO folder_a and folder_b exists, but folder_c not
)

这篇关于多"如果"在批处理文件语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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