2
votes

I begin by saying that i am new in using Inno setup and i am sorry if this is a dumb question. I am trying to delete a folder with all it's sub-folders and files during the uninstallation of an application. The specific folder is created in My Documents when the application runes for the first time. For deleting it i am using the "Delltree" function:

    procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
var Ceva: integer;
begin
  case CurUninstallStep of
    usUninstall:
      begin
        MsgBox('CurUninstallStepChanged:' #13#13 'Uninstall is about to start.', mbInformation, MB_OK)
         end;
    usPostUninstall:
      begin
            Ceva := MsgBox('CurUninstallStepChanged:' #13#13 'Do you want to delete the folder ?.', mbConfirmation, MB_YESNO)
        if Ceva = idYES  then
        DelTree('{userdocs}\myfolder', True, True, True);           
      end;
  end;

For some reason the "{userdocs}" constant appear not to be working. If i put the exact path to the folder "DelTree('C:\Users\myuser\Documents\myfolder', True, True, True); " everything is working fine.

1

1 Answers

2
votes

When you use a constant in code, you need to use the ExpandConstant function. So your Deltree command should be:

DelTree('ExpandConstant({userdocs})\myfolder', True, True, True);

Alternatively, have you looked at the [UninstallDelete] section? It can delete a directory and files at uninstall time without the need for code.