Archive: Removing parent directories


Removing parent directories
  Our current installation installs our product to something like:

C:\Program Files\CompanyName\ProductName

During the uninstall,

  RMDir/R "$INSTDIR" 

will only remove the ProductName folder, leaving an empty CompanyName folder.

Is there a smart way to remove the folder CompanyName? As far as I can tell there is no way to capture which directories are being created by the installer. Hardcoding
  RMDir/R "$INSTDIR"

RMDir /R "C:\\Program Files\\CompanyName"
isn't a viable solution, because the problem still exists for non-default installations that have subfolders (and this problem also exists for removing shortcuts).

Also, doing something like
StrCpy $R0 $INSTDIR

loop:
RMDir "$R0"
IfErrors goto done
StrCpy "$R0" "$R0\\.."
goto loop
done:
isn't a (completely) viable solution because you might end up deleting an empty directory the installer didn't create, that the user doesn't want deleted.

Suggestions?

http://nsis.sourceforge.net/archive/...instances=0,11


You can use GetParent from the useful functions appendix (or from the link rainwater posted), use it on $INSTDIR and if what comes out is $PROGRAMFILES\CompanyName then you can delete it. I suggest you don't use /r so whatever the user put in there will stay.


Right, but that is pretty much the same thing as the RMDIR $R0\.. option.

What I need to know is whether or not the parent was created by the installer, what would be usefull (a suggestion) is that NSIS somehow keeps track of the files/directories it created, so they can be removed during the uninstall. I'm certain this is how most installers/uninstallers handle it.


That's not the same as $R0\.. because you check against $PROGRAMFILES\CompanyName. If you want to know exactly which directories were created you can make a little recursion that will take the directory path apart and try to create every directory from the smallest part to the largest and final part. Use the latest CVS version and IfErrors after you create the directory to know if it was created or not. Save that somewhere and delete it upon uninstallation.


Right, but comparing it against CompanyName won't work if the user has entered in anoter value for "CompanyName". Right?

That's a good suggestion about creating the directories manually. Thanks :)