Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete files in batch with without error message

I use the command

del "info*"  

to delete a group of files starting with "info". The problem is that sometimes there is at least one of these files that exist,therefore they are deleted and others times no files exist and and error message happens. I need my script must not block if these files don't exist.

I look at options for del /? but nothing help me go ahead.

Could you help me, please?

like image 444
new Avatar asked May 14 '13 20:05

new


People also ask

Why is %% used in batch file?

Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. Required. Specifies one or more files, directories, or text strings, or a range of values on which to run the command.

How do I force delete a batch file?

Force delete using WindowsWith the command prompt open, enter del /f filename , where filename is the name of the file or files (you can specify multiple files using commas) you want to delete.


2 Answers

Did you tried something like this :

IF EXIST [Filename] (     del [Filename] ) ELSE (     ... ) 
like image 200
RelevantUsername Avatar answered Sep 17 '22 17:09

RelevantUsername


try this:

del "file to delete" >nul 2>&1 del "info*" >nul 2>&1 

This sends normal and error messages to nul.

del "file to delete" 2>nul del "info*" 2>nul 

This sends only error messages to nul.

like image 26
Endoro Avatar answered Sep 18 '22 17:09

Endoro