Archive: Delete user created Sub-folders keeping files in the $INSTDIR


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,


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'


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,


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


Thanks a lot. Yeah it seems to be useful reference material. Though it will be not that easy I think.


It wouldn't worth if it would be easy :)


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]


Try !insertmacro un.Locate
Also you may open the included FileFunc.nsh and examine the required definitions for installer/uninstaller :)


Oh! forgot to tell that I did used:
!insertmacro un.Locate

but its not working.


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!


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

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.


But yours code is much cleaner.
Actually the code is from the included examples :) (thanks goes to Instructor)