Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSIS - Delete all files except one file

Tags:

nsis

Could any one clarify me that, when uninstalling I need to delete everything form the Installation folder except the License file. How can I do it with NSIS scripting?

Thanks Regards, RoboAlex.

like image 932
RoboAlex Avatar asked Dec 01 '10 06:12

RoboAlex


2 Answers

Instead of opening the file, as in Anders' third point, I'd do it this way:

Rename $INSTDIR\license.txt $PLUGINSDIR\license.txt
RMDir /R $INSTDIR # Remembering, of course, that you should do this with care
CreateDirectory $INSTDIR
Rename $PLUGINSDIR\license.txt $INSTDIR\license.txt

Depending on when it gets to the file it can't delete, RMDir /R may leave most of it behind, as I believe it will stop when it can't delete something; this way will get rid of it all properly. This will also lose the directory stats, but that's probably not important.

I'd recommend one of Anders' first two solutions over this, though. They're more precise.

like image 131
Chris Morgan Avatar answered Nov 12 '22 03:11

Chris Morgan


Off the top of my head, there are 3 ways to do this:

  • Use Delete on one file at the time on a list generated at compile time with !system etc
  • Use FindFirst/FindNext/FindClose at runtime and Delete everything except the license based on filename
  • A bit of a hack, but you should be able to open the license file for write/append, then Delete/RMDir will not be able to delete the file since it has a open handle.
like image 38
Anders Avatar answered Nov 12 '22 05:11

Anders