Pregunta

I've been working on a batch file to search for a folder and if it exhist do a goto command with that variable. It works, but every time you get spammed with: "There is no disk in the drive. Please insert a disk into drive to \device\hardisk1\dr21 and so on. Is there a way I can prevent this message from popping up?

Batch File:

@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
  )
)
¿Fue útil?

Solución

if you're calling this from the command line then going:

batch.bat arguments 2> NUL

will redirect all error messages to the NUL device, which will prevent them from popping up.

or create a wrapper subroutine within the batch file itself, for example:

@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

will not return an error because the subroutines error messages are going to NUL

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top