我正在尝试创建一个脚本,搜索插入计算机的所有设备并查找该文件,然后在设备找到或未找到时回显。
for %%d in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
if exist "%%d:\common\" echo Device was found on %%d:
)else(
echo Device was not found
)
pause
这段代码看起来似乎没有任何帮助吗?
答案 0 :(得分:0)
您输错了:使用else
而不是esle
。
你缺少一些括号。试试:
for %%d in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
if exist "%%d:\common\" (
echo Device was found on %%d:
) else (
echo Device was not found
)
)
pause
答案 1 :(得分:0)
您的代码中存在一些语法问题:
else
之前摆脱相应的右大括号。)else
(正如@dystroy已提到的)else
之后的大括号前面留一个空格。提示:正确的格式和缩进会暗示某些问题。
您的代码应如下所示:
for %%d in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
if exist "%%d:\common\" (
echo Device was found on %%d:
) else (
echo Device was not found
)
)
pause