-4

How do I remove a batch file I just used with a batch code line? Like a code that does this:

remove thisbat.bat

Thanks in advance.

user3149725
  • 1
  • 1
  • 2
  • 1
    Do what this guy does: http://stackoverflow.com/questions/2888976/how-to-make-bat-file-delete-it-self-after-completion – kmort Dec 31 '13 at 16:13

1 Answers1

5

Some people will tell you to just put

DEL "%~f0"

on the last line, but that usually causes an error in that the BAT file can no longer find itself. You should use the following statement on the last line of your BAT file, because after it hits this line your BAT file is gone:

start /b "" cmd /c del "%~f0"&exit /b

This will launch a new delete process within the same console, thus eliminating any "file can no longer be found" errors.

Johnny Bones
  • 8,786
  • 7
  • 52
  • 117