A file delete it's self. How to?

You can talk about anything related to LB Booster here, not covered in another category
sarmednafi
Posts: 37
Joined: Fri Apr 06, 2018 6:27 am

A file delete it's self. How to?

Post by sarmednafi »

Dear Group,

I just wrote a tiny program saying Beep. After that I wont the program to delete it's self. Is there any away to do that?
Regards

Sarmed
guest
Site Admin
Posts: 193
Joined: Tue Apr 03, 2018 1:34 pm

Re: A file delete it's self. How to?

Post by guest »

sarmednafi wrote: Wed Mar 06, 2024 10:41 am I just wrote a tiny program saying Beep. After that I want the program to delete itself. Is there any away to do that?
As this is a general Windows question, and not specific to LBB (or LB), did you try Google? A search finds several hits for me.

The simplest approach found by Google seems to be to spawn a command, immediately before quitting, which waits for a few seconds and then deletes the executable. Something like this might work, although I've not tried it:

Code: Select all

RUN "cmd.exe /C timeout /t 10 > NUL & del /f /q ""\mypath\myprog.exe"""
END
xxgeek
Posts: 11
Joined: Tue Nov 28, 2023 1:36 pm

Re: A file delete it's self. How to?

Post by xxgeek »

Something like this might work, although I've not tried it:

Code: Select all

RUN "cmd.exe /C timeout /t 10 > NUL & del /f /q ""\mypath\myprog.exe"""
END
I have tried this and can confirm it works.
Thanks for posting this. It will be of use to me in future.
sarmednafi
Posts: 37
Joined: Fri Apr 06, 2018 6:27 am

Re: A file delete it's self. How to?

Post by sarmednafi »

Dear Richard,
Thank you for your help.
I spent all yesterday trying to get logged in the forum < https://lbb.bbcbasic.net/forum/ > I completely failed, and get sad, thinking Richard became angry of me and blocked me, Or Richard is Busy so he put the forum into freeze mode till I saw a post from geek. What's going on?
Then I log in using < https://lbbooster.com/forum/ > its worked ...

How ever, Richard I do searched in google till I found my self Lost so I asked the group for help. I wish if you put the link of the page you found the delete CMD on it ... any way your help is Great and I thank you very much.

Thank you Geek for your response.

All the Best
xxgeek
Posts: 11
Joined: Tue Nov 28, 2023 1:36 pm

Re: A file delete it's self. How to?

Post by xxgeek »

Just to add some more info on this.......
The syntax for Liberty Basic is a little different than for LB Booster,
The Liberty Basic syntax will work with LB Booster as well as Liberty Basic
The LB Booster syntax will not work with Liberty Basic. Syntax errors with quotes in quotes.

I wrote this little code to show it works.
It hides the command window too.
I have got away with a 2 second delay in the CMD commandline, and a .8 second delay in the Basic code.
Depending on your hardware, you may need to adjust both the CMD delay, and the Basic delay

,hide - at the end of the line hides the command window

Code: Select all

'This code will delete it's own Executable File (.exe)
'and then opens Windows FileManager to DefaultDir$

'For best results...
'Save this file as        deleteMeSelf.bas
'THEN   -  Use    Run > Make Executable..  in the LBB IDE Menu   (save to the default dir)
'THEN  -  Navigate to the created deleteMeSelf.exe in DefaultDir$ file and Click it.
'it deletes itself - then opens a new windows filemanager to DefaultDir$ to show it works.

nomainwin
'RUN "cmd.exe /C timeout /t 2 > NUL & del /f /q ""deleteMeSelf.exe""",hide     'works with LBB Only
RUN "cmd.exe /C timeout /t 2 > NUL & del /f /q "+chr$(34)+"deleteMeSelf.exe"+chr$(34),hide   'works with LB and LBB
timer 800, [flowDelay]  'a .8 second delay before opening Explorer - gives time for cmd to delete the file
  wait

[flowDelay]
timer 0
'Check with filemanager
run "explorer ";DefaultDir$
END  
guest
Site Admin
Posts: 193
Joined: Tue Apr 03, 2018 1:34 pm

Re: A file delete it's self. How to?

Post by guest »

sarmednafi wrote: Fri Mar 08, 2024 5:20 am I spent all yesterday trying to get logged in the forum < https://lbb.bbcbasic.net/forum/ > I completely failed...
Then I log in using < https://lbbooster.com/forum/ > its worked ...
I think this has to do with the CAPTCHA. When you log into the forum, there is a Google Invisible reCAPTCHA to check that you are a human rather than a robot. One of the checks it performs is that you are logging in at the expected URL: it accepts both lbbooster.com/forum and bbcbasic.net/lbb/forum but not lbb.bbcbasic.net/forum.

I wonder why you were using that URL. Is it published somewhere online?
sarmednafi
Posts: 37
Joined: Fri Apr 06, 2018 6:27 am

Re: A file delete it's self. How to?

Post by sarmednafi »

>> I wonder why you were using that URL. Is it published somewhere online?


No, Dear Richard It was an old shortcuts I was using before you made the changes.

Regards
guest
Site Admin
Posts: 193
Joined: Tue Apr 03, 2018 1:34 pm

Re: A file delete it's self. How to?

Post by guest »

sarmednafi wrote: Thu Mar 21, 2024 5:04 am It was an old shortcuts I was using before you made the changes.
Everything's moved. I no longer use the old hosting service (meirhosting.net) because they had a monthly bandwidth limit and occasionally that was exceeded, causing the site to become unavailable. I've moved to a host with no formal bandwidth limit, which hopefully should be more reliable. All the published URLs should still work, but privately-created shortcuts may not.
sarmednafi
Posts: 37
Joined: Fri Apr 06, 2018 6:27 am

Re: A file delete it's self. How to?

Post by sarmednafi »

Thank you for the clarification Richard.