cmd.exe:复杂的条件? [英] cmd.exe: complex conditions?

查看:22
本文介绍了cmd.exe:复杂的条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 DOS 批处理文件中,在 IF 语句中,是否可以使用 AND 或 OR 组合两个或多个条件?我找不到任何相关文档

in DOS batch files, In an IF statement, is it possible to combine two or more conditions using AND or OR ? I was not able to find any documentation for that

Edit - help if 和 MS 文档没有说明在 if 中使用多个条件.

Edit - help if and the MS docs say nothing about using more than one condition in an if.

我想 AND 的解决方法是这样做

I guess a workaround for AND would be to do

if COND1 (
  if COND2 (
    cmd
  )
)

但这正是我想要避免的.

but this is exactly what I'm trying to avoid.

推荐答案

不,没有更简单的方法.

No, there is no easier way.

对于,你也可以直接链接它们而不引入块:

For and you can also just chain them without introducing blocks:

if COND1 if COND2 ...

坦率地说,这并不比

if COND1 and COND2 ...

然而,对于 or 确实会变得更丑:

However, for or it gets uglier, indeed:

set COND=
if COND1 set COND=1
if COND2 set COND=1
if defined COND ...

或:

if COND1 goto :meh
if COND2 goto :meh
goto :meh2
:meh
...
:meh2

我曾经看到一个批处理预处理器,它使用类似 C 的语法来处理控制流和批处理内容,然后将这些条件转换为多个跳转和检查.但是,那是 DOS 批处理文件,在 Windows 环境中几乎没有用处.

I once saw a batch preprocessor which used C-like syntax for control flow and batch stuff in between and then converted such conditionals into multiple jumps and checks. However, that thing was for DOS batch files and was of little to no use in a Windows environment.

这篇关于cmd.exe:复杂的条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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