Page 1 of 1

self-delete line

Posted: 01 Jan 2011 21:14
by scienceguru1.bat
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!

Re: self-delete line

Posted: 01 Jan 2011 21:36
by aGerman
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

Re: self-delete line

Posted: 01 Jan 2011 21:40
by scienceguru1.bat
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?

Re: self-delete line

Posted: 01 Jan 2011 21:53
by aGerman
%~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