Delete SFX file after extraction

1

I created a SFX to extract some files. After the extraction, I need that the SFX file is deleted. As far as I have seen, WinRar does not offer such option. So I thought to run some DOS command -prompt (like bat).

This is my code so far (not working):

SETUP=cmd /c del /f /q "file-to-delete"

It opens the cmd, flashes and then closes...

Someone with a similar problem: http://www.msfn.org/board/topic/34506-sfx-remove-file-after-extraction/

Rafael Vidal

Posted 2013-06-05T09:38:03.237

Reputation: 223

is your SETUP= a WinRar directive? Ensure the full path to the file is included. – foxidrive – 2013-06-05T13:34:57.923

Yes, "SETUP=" is AN winrar diretive and it allows to run a specific program after the SFX automatic extraction, which can be "Setup.exe" or "Install.exe" or "script.bat", etc... the path is fine I just can't find the way to make it works – Rafael Vidal – 2013-06-05T13:45:17.737

Your problem is that the SFX is still running, so if you try to delete it you're only going to end up with an Access Denied error. – Karan – 2013-06-06T04:42:34.167

Karan, that's not the case. Winrar have specicif directives to be used BEFORE, DURING or AFTER the exctraction process. In this case, the SETUP directive is excevuted at the ende (after SFX has finished). So there is no problem to delete the file. By the way, foxidrive has the exactly solution. Thank you by the way. – Rafael Vidal – 2013-06-06T23:32:37.083

1Hmm, wonder why cmd doesn't work but cmd.exe does (with or without the full path, former is what %comspec% contains). So all you had to do was change your code to SETUP=cmd.exe /c del /f /q "name-of-sfx". – Karan – 2013-06-08T00:10:35.540

Answers

1

See if this works - include the accurate path to the file and see if it deletes it. If it does then you can try relative paths.

SETUP="%comspec%" /c del "c:\program location\file-to-delete"

If that fails then include this command in a bat file located where the file is and then use the bat file to delete the SFX file, in the WinRar directive.

@echo off
del "file-to-delete"

foxidrive

Posted 2013-06-05T09:38:03.237

Reputation: 271

PERFECT! "%comspec%" /c del "c:\program location\file-to-delete" made the trick. But how did you know? – Rafael Vidal – 2013-06-06T23:33:12.710

0

you must select the GUY mode of the SFX archive. 32 bit rar mode on 64 machine will not delete 64 bit rar on 64 will delete the file.

otherwise you can use powershell to delete a folder in the cmd.

powershell "rd -r \"%PROGRAMFILES%\company\folder\""

user1133340

Posted 2013-06-05T09:38:03.237

Reputation: 1