如何在批处理中使用“IF EXIST”

3

我需要运行一个Windows批处理文件来检查一堆文件是否存在。我写了以下批处理文件代码:

dir

if exist {"help/user/Content/learning_home.htm"} { echo file exists} ELSE {echo File Deleted}

if exist {"./archibus.war"} {echo File not deleted!} ELSE {echo File Deleted}
if exist {"./build.xml"} { echo file exists} ELSE {echo File Deleted}

当我执行批处理文件时,目录列表正确显示,但其余命令只会被显示回命令行。我感觉自己错过了一些基本的东西。如有建议,请不吝赐教。
1个回答

3
请使用圆括号而不是花括号。
if exist "help/user/Content/learning_home.htm" (echo file exists) ELSE (echo File Deleted)

if exist "./archibus.war" (echo File not deleted!) ELSE (echo File Deleted)
if exist "./build.xml" (echo file exists) ELSE (echo File Deleted)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接