我可以在批处理文件中使用“或”/“和”来指定多个条件吗?
如果不是那么复杂,我至少可以使用如下的东西:
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 < value2Basically 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 :DoneTo 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 :DoneThe labels are of course arbitrary, and you can choose their names as long as they are unique.
更多推荐
发布评论