English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

how can prevent my batch file with the del. command from deleting itself until the end??

2007-07-05 13:37:49 · 2 answers · asked by Thirsty Attorney 1 in Computers & Internet Programming & Design

and how can i make it delete itself when done?

2007-07-05 14:29:07 · update #1

2 answers

There are a couple ways to do what you want.

1) Prevent a batch from deleting itself when you perform a "del." or "del ."

Like the other answerer indicated, you could put the batch in a different directory, then specify the target directory when deleting.

Or,
If you really want to keep the batch file in the target directory, then you could add one line to your batch

attrib mybatch.bat +r

That would add the read-only attribute to your batch file (use your bat's filename). By default, the "del" command does not delete read-only files.

2) How to get your batch to delete itself. This is also done with a single line,

start cmd /c del mybatch.bat /f

This starts a separate command processor that tells the batch to delete itself. The "/f" switch forces the batch to delete any files that are read-only, like itself from the prior command.

These two commands do the two things that you asked,
The batch doesn't delete itself on a global wildcard delete
The batch does delete itself when you want it to.

One final item, if you don't want to have to answer Y/N when you do your delete, then add the "/q" switch and it will delete things quietly, meaning without asking for confirmation.

del. /q

Hope that helps.

2007-07-09 00:16:02 · answer #1 · answered by Kevin 7 · 5 0

Put the .bat file in another folder. Then when writing the .bat direct the text to c/whatever/whatever..del *.*...
The .bat does not have to exist within a specific directory...And it can be directed to delete files in another directory...

I'm not sure it can delete itself because it will be open while running so access will be denied.....But doing it as above there shouldn't be a need to delete it.....There will be no trace evidence of what was in c/whatever/whatever...Just an empty folder...


The whole reason for the .bat file was to routinely do something (In the DOS days.)...Ie...Move, edit, delete,copy,...whole batches of data efficiently...

2007-07-05 13:49:14 · answer #2 · answered by Anonymous · 1 0

fedest.com, questions and answers