To suppress output, use redirection to NUL
.
There are two kinds of output that console commands use:
standard output, or stdout
,
standard error, or stderr
.
Of the two, stdout
is used more often, both by internal commands, like copy
, and by console utilities, or external commands, like find
and others, as well as by third-party console programs.
>NUL
suppresses the standard output and works fine e.g. for suppressing the 1 file(s) copied.
message of the copy
command. An alternative syntax is 1>NUL
. So,
COPY file1 file2 >NUL
or
COPY file1 file2 1>NUL
or
>NUL COPY file1 file2
or
1>NUL COPY file1 file2
suppresses all of COPY
's standard output.
To suppress error messages, which are typically printed to stderr
, use 2>NUL
instead. So, to suppress a File Not Found
message that DEL
prints when, well, the specified file is not found, just add 2>NUL
either at the beginning or at the end of the command line:
DEL file 2>NUL
or
2>NUL DEL file
Although sometimes it may be a better idea to actually verify whether the file exists before trying to delete it, like you are doing in your own solution. Note, however, that you don't need to delete the files one by one, using a loop. You can use a single command to delete the lot:
IF EXIST "%scriptDirectory%*.noext" DEL "%scriptDirectory%*.noext"