Archive: How can I easily delete all files created by the installer?


How can I easily delete all files created by the installer?
Upon hearing a horror story of a user that accidentally installed his shareware application in the root of the hard disk, only to have the uninstaller "RMDir /r" his entire hard disk I decided I don't want to use the /r option anymore.

Am I forced to manually delete each and every single file I create manually with a "Delete" command or is there some easy way to have the uninstaller delete all the files that were created during the installation, but none of the other files it finds?

Thanks and best regards,
Diodor Bitan


Why did you use AllowRootDirInstall true? If you don't use that, the user won't be able to install to the root directory.

You can also use a macro which both includes a file and writes its delete line to another file. You can then include that file in the uninstaller to have all the files copied deleted.

!macro File file
File "${file}"
!system 'echo Delete "$INSTDIR\${file}" >> $%TEMP%\uninstaller.nsh'
!macroend

Section uninstall
!include $%TEMP%\uninstaller.nsh
SectionEnd


Original post by kichik
Why did you use AllowRootDirInstall true? If you don't use that, the user won't be able to install to the root directory.
I'm glad to hear that. The horror story wasn't about my app, so then it seems I was safe in this regard. I still don't want to use either of "RMDir /r" or "Delete *.*" anymore

You can also use a macro which both includes a file and writes its delete line to another file. You can then include that file in the uninstaller to have all the files copied deleted.

!macro File file
File "${file}"
!system 'echo Delete "$INSTDIR\${file}" >> $%TEMP%\uninstaller.nsh'
!macroend

Section uninstall
!include $%TEMP%\uninstaller.nsh
SectionEnd
That's nice! I still have to enter a separate line for each file in the application directory, right?

I wanted to automate this somehow - right now my script adds files with File 'C:\path\*.*' commands, which is quite convenient as the files change from version to version.

I guess I'll have to make an external script that scans all the files in the directory and creates files that will therafter be included in my nsis script.

Thanks to your help I'll be able to call the external script from the nsis one using the !system command, so that should be the end of that :)

[edit]never mind, you found the solution on your own[/edit]

You can create something similar to, or even based on http://forums.winamp.com/showthread....hreadid=150770


Done!

I add the files with an elegant "File /r c:\*.*" in my installing section. Then in the uninstall section, I add

!system "delsave.bat"
!include "delsave.nsh"


The delsave.bat program:

dir /s /b /a-d c:\pax\*.* > temp.txt
lua -e "io.input ('temp.txt') io.output ('delsave.nsh') dir = 'c:\\pax'" -l delsave.lua
del temp.txt


Which in turns calls the delsave.lua program:

len = string.len (dir)

for line in io.lines () do
assert (dir == string.sub (line, 1, len))
io.write ('Delete "$INSTDIR', string.sub (line, len + 1), '"\n')
end

:)