如何在批处理文件中的“If”中使用多个条件?(How can I use multiple conditions in “If” in batch file?)

编程入门 行业动态 更新时间:2024-10-15 02:30:43
如何在批处理文件中的“If”中使用多个条件?(How can I use multiple conditions in “If” in batch file?)

我可以在批处理文件中使用“或”/“和”来指定多个条件吗?

如果不是那么复杂,我至少可以使用如下的东西:

if value1 < value < value2

基本上我的目的是检查当前系统时间是否落在某个时间间隔(准确地说是2.05 AM和7.55 AM),如果是,则执行某些命令。

Can I specify multiple conditions with "or"/"and" in batch file if block?

If not that complex, can I at least use something like:

if value1 < value < value2

Basically my purpose is to check whether current system time falls in a certain interval(2.05 AM and 7.55 AM to be precise) and if it does, to execute certain commands.

最满意答案

添加到dbenham的答案,您可以使用if和goto语句的组合模拟两个逻辑运算符(AND,OR)。

测试条件1和codition2

if <condition1> if <condition2> goto ResultTrue :ResultFalse REM do something for a false result goto Done :ResultTrue REM do something for a true result :Done

要测试condition1或codition2

if <condition1> goto ResultTrue if <condition2> goto ResultTrue :ResultFalse REM do something for a false result goto Done :ResultTrue REM do something for a true result :Done

标签当然是任意的,只要它们是唯一的,你可以选择它们的名字。

Adding to dbenham's answer, you can emulate both logical operators (AND, OR) using a combination of if and goto statements.

To test condition1 AND codition2:

if <condition1> if <condition2> goto ResultTrue :ResultFalse REM do something for a false result goto Done :ResultTrue REM do something for a true result :Done

To test condition1 OR codition2:

if <condition1> goto ResultTrue if <condition2> goto ResultTrue :ResultFalse REM do something for a false result goto Done :ResultTrue REM do something for a true result :Done

The labels are of course arbitrary, and you can choose their names as long as they are unique.

更多推荐

本文发布于:2023-08-07 08:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1462869.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   批处理文件   条件   如何在   batch

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!