如何在Windows Batch中创建“ if and if”语句?

约书亚记

这更多是一个好奇心问题,但是Windows Batch中是否有一种方法可以发出if file.ext exists && if file2.ext exists (echo Yes.) else (echo No.)-type命令?

瓦西夫

是的,您可以实现AND / OR运算符,例如:

if exist file1.ext (
  if exist file2.ext (
    echo Yes, both file1.ext and file2.ext exist
  ) else (
    echo No, both file1.ext and file2.ext not exist
  )
) else (
  If exist file2.ext (
    echo file1.ext does NOT exist but file2.ext does exist
  )
)

要检查File2.ext是否存在而file1.ext不存在,请执行以下操作:

if exist file1.ext (
  if not exist file2.ext (
     echo file1.ext does exist but file2.ext does NOT exist
  )
)

其他关键字的位置很重要!

阅读更多:

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章