Delete SFX file after extraction

9,822

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"
Share:
9,822
Rafael Vidal
Author by

Rafael Vidal

Updated on September 18, 2022

Comments

  • Rafael Vidal
    Rafael Vidal over 1 year

    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/

    • foxidrive
      foxidrive almost 11 years
      is your SETUP= a WinRar directive? Ensure the full path to the file is included.
    • Rafael Vidal
      Rafael Vidal almost 11 years
      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
    • Karan
      Karan almost 11 years
      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.
    • Rafael Vidal
      Rafael Vidal almost 11 years
      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
    Rafael Vidal almost 11 years
    PERFECT! "%comspec%" /c del "c:\program location\file-to-delete" made the trick. But how did you know?