Mar 152008

Commands such as deleting all files can complicate batch files because the system prompts for confirmation.

For example check the following command

del *.* replies with *.*, Are you sure (Y/N)?

Now if you don’t want to display prompt By using echo this will automatically reply for you

echo y | del *.*


del /q *.*

To supress the “File Not Found” error when trying to delete files from an empty directory, use this code instead:

if exist *.* echo y| del *.*


if exist *.* | del /q *.*

During the execution of your batch files, users can see your commands on the screen. Most of the time this is good for debugging purposes; however, often it’s better to run your batch file silently.

Solution 1

Any command that is followed by “> nul” will not be shown on the screen. The greater sign directs the output to null (nowhere).

For example, copy *.* *.bak will show you as it copies all the files in the directory and renames them with the bak extension.

copy *.* *.bak > nul will silently complete its work without placing anything on the screen.

Solution 2

It will redirect STDOUT to null. Errors will still be displayed. As an example, run dir badfile.txt >nul and you will still see “File not found” displayed. That’s because errors are written to STDERR

To redirect STDERR to nul as well, try this:

dir badfile.txt > nul 2>&1

Of course you may want to see the errors. So a better tack to take could be to write to a log file

dir badfile.txt >log.txt 2>&1

Incoming search terms:

 Leave a Reply



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>