需要协助批处理文件:检测现有驱动器上的文件夹

时间:2013-01-22 23:31:11

标签: windows batch-file drive

我一直在处理一个批处理文件来搜索一个文件夹,如果它exhist用该变量做一个goto命令。它有效,但每次你收到垃圾邮件: “驱动器中没有磁盘。请将磁盘插入驱动器\ device \ hardisk1 \ dr21,依此类推。有没有办法阻止弹出这个消息?

批处理文件:

@echo off
setLocal Enabledelayedexpansion


for %%d in (a b 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:\custom\ (
  ECHO Device Found : %%d
  )
)

1 个答案:

答案 0 :(得分:0)

如果你从命令行调用它,那么:

batch.bat arguments 2> NUL

会将所有错误消息重定向到NUL设备,这会阻止它们弹出。

或在批处理文件本身中创建一个包装器子例程,例如:

@echo off
setLocal Enabledelayedexpansion

CALL :SUB_A 2> NUL
GOTO :EOF

:SUB_A
for %%d in (a b 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:\custom\ (
      ECHO Device Found : %%d
    )
)
GOTO:EOF

不会返回错误,因为子例程错误消息将转到NUL