Bardy
31st August 2007 05:29 UTC
About RMDir the installation folder
Hi everyone,
I am a fresh for NSIS. There is a difficulty for me about RMDIR the installation folder. For example, if I write code "RMDir "$INSTDIR" in the script. Then set "D:\XXX\XXX\installation" as the installation folder when I implement the installation. After I uninstall, the folder "D:\XXX\XXX" will still exist.
How can I solve this problem? Please help me.
BR
cheryll
31st August 2007 07:31 UTC
Well, RMDir will only delete the specified folder. If you secified D:\xxx\xxx\installation as you instdir, then it will only delete \installation. If you want to remove the other folders as well just repeat the process:
RMDir "D:\xxx\xxx"
RMDir "D:\xxx"
Bardy
31st August 2007 08:18 UTC
Thank you for your answer. But you know, I just wrote code "RMDIR $INSTDIR". Before someone specified the folder when they implemented the instllation, I don't know what directory they want. Perhaps they will choose "D:\aaa\installation" or "C:\bbb\ccc\installation". I just wanna uninstallation can remove any folder they chose.
cheryll
31st August 2007 08:49 UTC
I do understand you point, but RMDir just deletes the topmost directory.I haven't bothered with something like this yet, cause most people probably wont put a lot of empty directorys befor the acctual folder.
But I guess you can use getParent. It will give you the next over- directory.
It's not very elegant, but it works. Perhaps someone else will have a better idea. I'm rather new to NSIS myself.
!include "FileFunc.nsh"
!insertmacro un.GetParent
[...]
RMdir $instdir
${un.GetParent} $instdir $R0
;first the directory then the variable where to put the parent
RMdir $R0
${un.GetParent} $R0 $R1
RMDir $R1
...etc.
Bardy
31st August 2007 08:59 UTC
Thank you very much!! You help me a lot.
Wizou
31st August 2007 13:04 UTC
Indirectly related note: I noticed that if you use SetOutPath "$PLUGINSDIR" during installation (this set the current directory), NSIS won't be able to remove this temporary plugins directory at the end of installation, so make sure you move out, for example with a SetOutPath "$INSTDIR", before ending installation
I guess a similar problem might occur if you SetOutPath "$INSTDIR" during uninstallation, you might then not be able to RMDir $INSTDIR
Because Windows won't let you remove a directory if current directory is still pointing to it
fluidz91
20th February 2008 11:19 UTC
I have the same issue.
I m afraid that with this method you can erase all the "Program Files" folder or even worst the root of drive !
By default, the install folder ($INSTDIR) is "$PROGRAMFILES\Company\ProductName" but it can be c:\company\productname or c:\productname or whatever
on uninstall section i do RmDir /r /REBOOTOK $INSTDIR and on my first exemple "$PROGRAMFILES\Company\" is left.
The use of GetParent seems to be dangerous when you don't know how many subfolders are created.
Any clue ?
Originally posted by cheryll
I do understand you point, but RMDir just deletes the topmost directory.I haven't bothered with something like this yet, cause most people probably wont put a lot of empty directorys befor the acctual folder.
But I guess you can use getParent. It will give you the next over- directory.
It's not very elegant, but it works. Perhaps someone else will have a better idea. I'm rather new to NSIS myself.
!include "FileFunc.nsh"
!insertmacro un.GetParent
[...]
RMdir $instdir
${un.GetParent} $instdir $R0
;first the directory then the variable where to put the parent
RMdir $R0
${un.GetParent} $R0 $R1
RMDir $R1
...etc.