Old 24th October 2007, 07:41   #1
General Barron
Junior Member
 
Join Date: Jul 2007
Posts: 3
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:

code:

@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!
General Barron is offline   Reply With Quote
Old 24th October 2007, 08:17   #2
pospec
Senior Member
 
pospec's Avatar
 
Join Date: Jun 2007
Location: Otrokovice, Czech Republic
Posts: 308
I use UnList.exe and it works fine. Described here: http://forums.winamp.com/showthread.php?postid=1862656
pospec is offline   Reply With Quote
Old 24th October 2007, 19:43   #3
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
You don't need a Wiki account to share. Anyone can create a page.

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump