On Fri, 23 Feb 2018 01:01:40 GMT, Paul Emmons wrote:
> I just discovered that, in Windows-XT, DIR returns errorlevel 1 if no files
> are found corresponding to the specifications submitted. (This is not true
> in Windows 98). I was about to kick myself for not knowing this long
> since, but the help for DIR does not document this useful feature.
ERRORLEVEL is originally designed to provide access to the exit code of a
program (i.e. external command). But later, either since Windows NT 3.x or
4.0, some internal commands also generate an exit code.
Microsoft tend to remove old information, even though the information still
applies to newer software versions. The documentations in Windows NT 3.x or
4.0 probably contains more details about CMD.EXE, then the ones in Windows
2000 and newer versions.
> In this case, "File Not Found" is displayed, presumably on the device
> STDERR. If the output of DIR is redirected to a file, this message does
> not appear in the file.
>
> My first question: I am using DIR in a batch file and am handling the file-
> not-found condition by means of the errorlevel. Is there a way to suppress
> the display of the message "File Not Found"?
You'll have to redirect the STDERR handle as mentioned by Auric_.
> Second question: What other commands might now return errorlevel codes that
> didn't use to do so?
Most internal commands which have the possibility of causing an error due to
not finding something from the given parameter, will generate an exit code.
e.g. CALL, CD, DEL, FOR, FTYPE, GOTO, PUSHD, TYPE, VOL, etc. But since at
least one command generates an exit code only if a specific parameter is
used (e.g. SET /P), other commands may do it too.
While you can create a batch file to check each and every command
parameters, IMO, it would be a pretty large project - considering that there
are many command parameters in total.