2

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Weasel
  • 23
  • 1
  • 3

1 Answers1

2

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.

mirtheil
  • 8,952
  • 1
  • 30
  • 29
  • Thanks a lot. DelTree('ExpandConstant({userdocs})\myfolder', True, True, True); worked perfectly. I tried the [UninstallDelete] section before posting the question and it worked, but i needed the user to chose if he wants to delete the specific folder or not. I did not find a method to do it with [UninstallDelete] – Weasel Jan 18 '11 at 12:25
  • For me it works in this syntax: DelTree(ExpandConstant('{userdocs}') +'\myfolder', True, True, True); – Afshin Moazami Mar 27 '15 at 18:38