Search code examples
inno-setuppascalscript

Deleting all files with some exceptions after installation with Inno Setup


How can I delete a series of files once the Run has been executed?

I want to delete a lot of DLL files and some other files because they are now in separate sub folders. But some of the DLL files are registered COM etc. Once Run has finished the old DLLs will not be registered anymore. So it will be safe for me to delete them.

InstallDelete is too early:
https://jrsoftware.org/ishelp/index.php?topic=installorder

So I want ability to delete *.dll but exclude pattern*.dll ONCE install finished.


I've seen a similar question:

Delete a file AFTER installation in Inno Setup

It seems I need to use something like:

[Code]
procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssPostInstall then begin
    DeleteFile(ExpandConstant('path'));
    ..

Ideally I want to delete:

  • {app}\*.dll
  • {app}\*.config
  • {app}\GoogleAuthAndSync.exe

But, I want to KEEP these files in the {app} folder:

  • {app}\MeetSchedAssist*.dll
  • {app}\VclStylesinno.dll

That is what I want to achieve. This is because the files are now being installed into distinct sub-folders and being managed there, and not all mixed up in the app folder.


Solution

  • The CurStepChanged(ssPostInstall) seems like the the right approach to me. So all you need on top of that is a way to delete all files, with some exceptions, right?

    Start here: Delete whole application folder except for "data" subdirectory in Inno Setup


    If you need to know how to test for partial filename (MeetSchedAssist*.dll):

    • If you need just one-off test, an ad-hoc condition like this will do:

      (CompareText(Copy(FindRec.Name, 1, 15), 'MeetSchedAssist') = 0) and
      (CompareText(Copy(FindRec.Name, Length(FindRec.Name) - 3, 4), '.dll') = 0)
      
    • If you have many tests, you can use MatchesMaskEx function from Inno Setup - Integer or Set/Range wildcard?:

      MatchesMaskEx('MeetSchedAssist*.dll', FindRec.Name)