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

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

问题描述

在DOS批处理文件,在如果语句,是有可能使用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

修改 - 帮助,如果和MS文档说任何关于使用一个以上的条件的,如果

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

我想一个解决办法,并会做

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 ...

然而,对于它变得丑陋,确实是:

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

我曾经看到一个批处理preprocessor它使用类似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天全站免登陆