Board logo

标题: [文本处理] 批处理if……else怎么用才正确啊? [打印本页]

作者: ryanliue    时间: 2010-8-30 11:10     标题: 批处理if……else怎么用才正确啊?

本帖最后由 pcl_test 于 2016-10-16 06:34 编辑
  1. REM --------------------------------------------------------------------------------------
  2. REM 检查必要文件
  3. REM --------------------------------------------------------------------------------------
  4. :check
  5. for %%i in (dism.exe oscdimg.exe imagex.exe xcopy.exe) do (
  6. %%i /? >nul
  7. if errorlevel 9009 (
  8. @echo 找不到%%i文件,请确保%%i位于本程序同一目录或系统可找到的目录中!
  9. pause >nul
  10. goto check
  11. )
  12. else (@echo 找到%%i文件!)
  13. )
  14. @echo 检查完毕!
复制代码
运行提示:
'else' 不是内部或外部命令,也不是可运行的程序或批处理文件。
作者: canyuexiaolang    时间: 2010-8-30 11:18

  1. if errorlevel 9009 (
  2.       @echo 找不到%%i文件,请确保%%i位于本程序同一目录或系统可找到的目录中!
  3.    pause >nul
  4.      goto check
  5. ) else (
  6.      @echo 找到%%i文件!)
  7. )
复制代码

作者: ryanliue    时间: 2010-8-30 11:22

晕!原来不能换行打else!
作者: Batcher    时间: 2010-8-30 12:59

帮助文档写的相当清楚
The ELSE clause must occur on the same line as the command after the IF.  For
example:

    IF EXIST filename. (
        del filename.
    ) ELSE (
        echo filename. missing.
    )





欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2