How can I use multiple conditions in “If” in batch file?

后端 未结 3 1861
余生分开走
余生分开走 2021-02-04 15:06

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 val         


        
3条回答
  •  無奈伤痛
    2021-02-04 15:56

    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  if  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  goto ResultTrue
        if  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.

提交回复
热议问题