suppressing "file not found" on Dir Command

  • Thread starter Thread starter TJT
  • Start date Start date
T

TJT

In Windows 2000, I am issuing a Dir command and I am directing the output to
a file, for example
dir xxx*.txt > c:\DirOutput.txt

In the case where there are no files found with the mask specified, I get a
message showing up in the CMD window "File not found".

It is expected that in some instances that there will be no files and of
course to the user, it looks like there is some kind of error. Is there
anyway to suppress this message?

Thanks in advance.
 
If you do not want the "File not found" message in your output file either,
use:

dir xxx*.txt > c:\DirOutput.txt 2>nul
 
dir xxx*.txt > c:\DirOutput.txt 2>&1

Austin M. Horst

This will suppress it, by redirecting Standard Error (STDERR) to the NUL
device.

dir xxx*.txt > c:\DirOutput.txt 2>nul
 
Back
Top