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