tags:

views:

331

answers:

4

In a Windows batch-file, this line:

del *.txt

Will give the error/warning message:

Could Not Find C:\*.txt

if there are no files matching the pattern *.txt. Is there a way to prevent that message?

+2  A: 

surround with an if exists...

or use a different delete utility {like 'rm' from the mks tools}

or take a look at forfiles.exe - that should do what you need.

phatmanace
+5  A: 

If you want to suppress all error messages, you can do this:

del *.txt 2>NUL
RichieHindle
A: 

Create one.

echo "Moo" > temporary-del-workaround.txt

Your removed file count will be off-by-one though.

Pasi Savolainen
A: 
if exist *.txt del *.txt
peterchen