Archive: Batch file to delete only installed files


Batch file to delete only installed files
Hello all, I'm a little lazy to make a Wiki account at the moment, but I have something here that others might find useful. I'm about to remove it from my HDD, so I thought I'd first post it here for others to use.

-------

Here is a windows batch file that is useful for making an uninstaller only delete the files that were added by the installer:


@echo off
set _b=%~dp0

del "%~dp0uninstall_files.nsh"

::list all files
dir /s /b /a:-d "%~dp0PROJECT" > __temp__
for /f "delims=" %%L in ('type __temp__') do call :delfile %%L

::list all folders

echo ;end > __temp2__
type __temp2__ > __temp3__

dir /s /b /a:d /o:n "%~dp0PROJECT" > __temp__
for /f "delims=" %%L in ('type __temp__') do call :delfolder %%L

type __temp2__ >> "%~dp0uninstall_files.nsh"
del __temp__
del __temp2__
del __temp3__
exit /b




:delfile

set _a=%*
set _a=%_a:*PROJECT\=%

echo delete "$INSTDIR\%_a%" >> "%~dp0uninstall_files.nsh"

goto :eof




:delfolder

set _a=%*
set _a=%_a:*PROJECT\=%

::reverse order of our output (add to top of file not bottom)
echo RMDir "$INSTDIR\%_a%" > __temp3__
type __temp2__ >> __temp3__
type __temp3__ > __temp2__

goto :eof



Here is how to use it:

-You need to have one big folder that you are installing via the 'file' instruction, including all files and subfolders. The outdir for this file must be the instdir. Let's say it is C:\myprogram.

-Place the batch file in the parent folder (in our example it would be C:\).

-Find/replace all of the words PROJECT in the above code, with the name of the folder to be processed (in our example it would be myprogram).

-Run the batch file. It will create a file called "uninstall_files.nsh".

-!include this file in the uninstall section of your .nsi file.

-------

Basically, the created .nsh file has a list of 'delete' instructions to delete all files added by the installer. Then it has a bunch of 'rmdir' instructions, to remove all directories, if they are empty.

It is simple, ugly and inelegant, but it works. Enjoy!

I use UnList.exe and it works fine. Described here: http://forums.winamp.com/showthread.php?postid=1862656


You don't need a Wiki account to share. Anyone can create a page.