Search code examples
nsis

NSIS - Delete all files except one file


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.


Solution

  • 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.