Can't get DelTree to delete a folder in Inno S

2019-07-06 16:36发布

I have a procedure DeleteTransferFolder which is called during the install using BeforeInstall in Inno Setup.

I know the procedure is called because I have a couple of MsgBox messages that show. But the DelTree does not delete the specified folder and sub-folders.

Any thoughts ?

procedure DeleteTransferFolder();
begin
  MsgBox('DeleteTransferFolder 1', mbInformation, MB_OK);

  if (FileExists ('{userdesktop}\RemedyNotes 1.0\RemedyNotes Old.remno')) then
    DelTree(ExpandConstant('{userdesktop}\RemedyNotes 1.0'), True, True, True);

  MsgBox('DeleteTransferFolder 2', mbInformation, MB_OK);    
end;

标签: inno-setup
1条回答
戒情不戒烟
2楼-- · 2019-07-06 17:35

You're missing the ExpandConstant call in the FileExists line, so it is returning false and thus the DelTree is not called.

The second MsgBox is shown because it is out of the conditional if (maybe due to the lack of a begin/end pair).

So, change your code to:

procedure DeleteTransferFolder();
begin
  MsgBox('DeleteTransferFolder 1', mbInformation, MB_OK);

  if (FileExists (ExpandConstant('{userdesktop}\RemedyNotes 1.0\RemedyNotes Old.remno'))) then
  begin
    DelTree(ExpandConstant('{userdesktop}\RemedyNotes 1.0'), True, True, True);
    MsgBox('DeleteTransferFolder 2', mbInformation, MB_OK);
  end;
end;
查看更多
登录 后发表回答