Inno setup 使用Inno安装程序卸载期间删除文件夹时出现问题

Inno setup 使用Inno安装程序卸载期间删除文件夹时出现问题,inno-setup,uninstallation,Inno Setup,Uninstallation,我首先要说的是,我对使用Inno设置是新手,如果这是一个愚蠢的问题,我很抱歉。 我试图在卸载应用程序期间删除一个文件夹及其所有子文件夹和文件。当应用程序第一次运行时,在我的文档中创建特定文件夹。要删除它,我使用“Delltree”函数: procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep); var Ceva: integer; begin case CurUninstallStep of us

我首先要说的是,我对使用Inno设置是新手,如果这是一个愚蠢的问题,我很抱歉。 我试图在卸载应用程序期间删除一个文件夹及其所有子文件夹和文件。当应用程序第一次运行时,在我的文档中创建特定文件夹。要删除它,我使用“Delltree”函数:

    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;

由于某种原因,{userdocs}常量似乎不起作用。如果我将文件夹“DelTree('C:\Users\myuser\Documents\myfolder',True,True,True);”的确切路径放入文件夹,则一切正常。

在代码中使用常量时,需要使用ExpandConstant函数。因此,您的Deltree命令应该是:

DelTree('ExpandConstant({userdocs})\myfolder', 真的,真的,真的)


或者,您是否查看过[UninstallDelete]部分?它可以在卸载时删除目录和文件,无需编写代码。

非常感谢。DelTree('ExpandConstant({userdocs})\myfolder',True,True,True);工作得很好。在发布问题之前,我尝试了[UninstallDelete]部分,它成功了,但我需要用户选择是否要删除特定文件夹。我没有找到一个方法来使用[UninstallDelete]对我来说,它的语法是:DelTree(ExpandConstant({userdocs}')+'\myfolder',True,True,True);