self-delete line

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
scienceguru1.bat
Posts: 44
Joined: 01 Jan 2011 20:54

self-delete line

#1 Post by scienceguru1.bat » 01 Jan 2011 21:14

I am trying to make a batch file that at the end will delete it's self. I have already tried once, using:

DEL %~dp0% [file name]

and deleted by desktop in the doings :oops: . I have a idea, but i wanted to check with someone else before I mess up again. My new idea is:

DEL %~dp0%%1 prompt $

Do you think this will work? If not, what should I do to fix it.
Thanks!

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: self-delete line

#2 Post by aGerman » 01 Jan 2011 21:36

A call /? should give you the answer.

Try
del "%~f0"
or
del %~fs0

Please don't tell me what this is good for, I don't wanna know :|

Regards
aGerman

scienceguru1.bat
Posts: 44
Joined: 01 Jan 2011 20:54

Re: self-delete line

#3 Post by scienceguru1.bat » 01 Jan 2011 21:40

i am trying to make a batch that downloads a file, then deletes it's self so it can' tbe share with others. the only file i am trying to delete in the end is the batch that i am running. will what you gave JUST delete the batch that is running?

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: self-delete line

#4 Post by aGerman » 01 Jan 2011 21:53

%~f0 expands to the file's own full name. Enclose it in double quotes if the path or file name contains spaces.
%~fs0 expands to the full short name.

You could always check it by ECHOing.

Code: Select all

echo "%~f0"
echo %~fs0


Regards
aGerman

Post Reply