回复 1# wxcute
这个用了不小的时间,差不点一个小时,学到了几点。
if exist 对目录同样有效,当文件不带扩展名时相当头痛,
因为一直使用肯定判断,导致不断出错。改用否定判断后,一次成功。
if errorlevel 要倒序使用,否则出错,原因我不知道。
经验:为程序每步+上echo 数字,if语句(尤其是多重判断)的运行流程一目了然,排查错误也方便许多,就是显得笨拙了一点。没办法,笨鸟先飞。- @echo off
- if not exist file (goto b) else (cd file)
- if errorlevel 1 (del file&md file&pause&goto :eof)
- if errorlevel 0 (cd..&rd file&goto b)
- :b
- cd.>file
- pause
复制代码
|