- NSIS Discussion
- Delete user created Sub-folders keeping files in the $INSTDIR
Archive: Delete user created Sub-folders keeping files in the $INSTDIR
Swapan Das
11th January 2007 08:14 UTC
Delete user created Sub-folders keeping files in the $INSTDIR
Hi!
I've come up with an un-installer issue where I'll not remove the main $INSTDIR but have to keep some files,have to delete some files,have to delete certain installer created sub-folders. Upto now its ok, but there is one peculiar condition now. There are certain sub-folders which are created by the software/user, and are not known to the Installer. How to delete those particular unknown sub-folders. I cannot pass the command :
RMDir /r /REBOOTOK $INSTDIR
as this will delete all the files,sub-folders, deleting my files and sub-folders which I intend to retain after the uninstall is performed.
Please note I can delete individual files like :
Delete "$INSTDIR\MyApp.exe"
and not pass wild card like:
Delete "$INSTDIR\*.*"
This will safe-guard of keeping the files I want to. But then simultaneously how can I remove the user/software created sub-folders?
Hope I was able to make to the situation clear!
Looking for Red Wine,Bruno or anyone of you who knows the solution for it.
With regards,
Red Wine
11th January 2007 09:04 UTC
I guess you probably know the names of the folders created by the software/user, so the easiest way is to add these folders to the uninstall section, e.g.
RmDir '$INSTDIR\a_folder_created_by_the_software/user'
or if they are not empty,
RmDir /r '$INSTDIR\a_folder_created_by_the_software/user'
Swapan Das
11th January 2007 10:36 UTC
Boss then I would not have asked this question. These sub-folders are unknown to me. It will be a different ball game, if try to do it by accessing the SQL database, to a particular table to locate for those folders. The bundled software keeps the records in one of its table in a SQL database. I want to do it through NSIS.
The issue is to retain some of my known sub-folders, and delete all the unknown sub-folders. Any idea?
Regards,
Red Wine
11th January 2007 10:53 UTC
then you should use at the end of your uninstall section the un.locate function in order to locate directories within $INSTDIR.
See NSIS manual http://nsis.sourceforge.net/Docs/AppendixE.html#E.1
Swapan Das
11th January 2007 11:41 UTC
Thanks a lot. Yeah it seems to be useful reference material. Though it will be not that easy I think.
Red Wine
11th January 2007 12:01 UTC
It wouldn't worth if it would be easy :)
Swapan Das
16th January 2007 11:27 UTC
Hi!
Sorry for this late post.
To delete the empty folders, I'm trying with this code.But its not working:
!insertmacro Locate
Section "Uninstall"
;... my all codes for uninstall first
;... finally
call un.LocateEmptyFolders
SectionEnd
Function un.LocateEmptyFolders
StrCpy $R2 0
StrCpy $R3 0
loop:
StrCpy $R1 0
${Locate} "C:\MyAppFolder" "/L=DE" "un.DeleteEmptyFolders"
IntOp $R3 $R3 + 1
IntOp $R2 $R2 + $R1
StrCmp $R0 StopLocate +2
StrCmp $R1 0 0 loop
IfErrors 0 +2
FunctionEnd
Function un.DeleteEmptyFolders
RMDir $R9
IntOp $R1 $R1 + 1
goto end
cancel:
StrCpy $R0 StopLocate
end:
Push $R0
FunctionEnd
Compilation is giving the following error:
Call must be used with function names starting with "un." in the uninstall section.
Usage: Call function_name | [:label_name]
Red Wine
16th January 2007 12:21 UTC
Try !insertmacro un.Locate
Also you may open the included FileFunc.nsh and examine the required definitions for installer/uninstaller :)
Swapan Das
16th January 2007 12:32 UTC
Oh! forgot to tell that I did used:
!insertmacro un.Locate
but its not working.
Swapan Das
16th January 2007 12:43 UTC
I'll check the documetation and will check the code.
Is it I've to use:
${un.Locate} "C:\MyAppFolder" "/L=DE" "un.DeleteEmptyFolders"
Let me try and get back!
Red Wine
16th January 2007 12:47 UTC
Name "My Application"
OutFile 'test.exe'
LicenseData '${NSISDIR}\License.txt'
LicenseBkColor 0xFFFFFF
InstallDir '$PROGRAMFILES\$(^name)'
!include FileFunc.nsh
!insertmacro un.locate
Page License
Page Directory
Page InstFiles
Section "boo"
SetOutPath '$INSTDIR'
CreateDirectory '$INSTDIR\boo'
CreateDirectory '$INSTDIR\boo\boo1'
CreateDirectory '$INSTDIR\alter boo'
CreateDirectory '$INSTDIR\alter boo\alter boo1'
WriteUninstaller '$INSTDIR\uninstall.exe'
SectionEnd
Section UnInstall
StrCpy $R2 0
StrCpy $R3 0
loop:
StrCpy $R1 0
${un.Locate} "$INSTDIR" "/L=DE" "un.LocateCallBack"
IntOp $R3 $R3 + 1
IntOp $R2 $R2 + $R1
StrCmp $R0 StopLocate +2
StrCmp $R1 0 0 loop
IfErrors 0 +2
MessageBox MB_OK 'error' IDOK +2
MessageBox MB_OK '$R2 directories were removed$\n$R3 loops'
SectionEnd
Function un.LocateCallBack
MessageBox MB_YESNOCANCEL 'Delete empty "$R9"?' IDNO end IDCANCEL cancel
RMDir $R9
IntOp $R1 $R1 + 1
goto end
cancel:
StrCpy $R0 StopLocate
end:
Push $R0
FunctionEnd
Swapan Das
16th January 2007 13:14 UTC
Thanks once again Red Wine!
So its ${un.Locate} , what I assumed is to be used here. My coding has not given any error during compilation this time.
But yours code is much cleaner. I wanted it automated, without any user interference so I didn't added the Message Box.
Red Wine
16th January 2007 13:21 UTC
But yours code is much cleaner.
Actually the code is from the included examples :) (thanks goes to Instructor)