0
votes

I've encountered a certain problem with leftovers after installation with inno setup.

I have set Flags: deleteafterinstall in [FILE] section, and it worked fine untill I added a some code that is renaming destination folder to different name durring installation, and since then Inno Setup is leaving all that files with that flag untouched which looks messy.

As a solution a created this simple batch file that I run in the end of installation via [CODE] section.

Clean_Up.bat:

del /s /f *.rej
del /s /f *.orig
del /s /f sed*
del /s /f *.patch
del /s /f *.exe
del /s /f *.bat

I'm copying this batch that way:

[FILE]
Source: "{#CompPath}\BatchFiles\Clean_Up.bat"; DestDir: "{app}\subfolder"; Flags: deleteafterinstall

I'm launching it with this:

[RUN]
Filename: "{app}\res_mods\Clean_Up.bat"; flags: runhidden;

The problem is that this batch is suppose to clean up also .batch files, and the result is that CleanUp.bat is also being removed and this is unwanted.

I wanted to solve this by copying it to {app} instead of {app}\subfolderand edit batch file to this:

del /s /f subfolder\*.rej
del /s /f subfolder\*.orig
del /s /f subfolder\sed*
del /s /f subfolder\*.patch
del /s /f subfolder\*.exe
del /s /f subfolder\*.bat

However it's giving me error: The system cannot find the file specified.

Can someone advise me how to make it work? I think the best way would be to rewrite this batch in pascal code and place in the code section, but I don't know how.

1
Why do you rename the folder anyway? Why don't you install files directly yo the res_mods? - Martin Prikryl
Would have to totaly rework how the installer is installing to that folder. We have a situation now where there are three different client versions and I want to support them all. There was no problem with that before, but now I must deal with a new situation so I'm seeking for a easiest and fastes solution for now before I rework it. - Jerry Zoden
So did my answer help? Or do you need something else? - Martin Prikryl

1 Answers

1
votes

At the moment you run the batch file, the subfolder is already renamed. So you need to use the new name:

del /s /f res_mods\*.rej
del /s /f res_mods\*.orig
...

Or use the WorkingDir parameter to run the batch file in the subfolder:

[Run]
Filename: "{app}\clean_up.bat"; WorkingDir: "{app}\res_mods"; Flags: runhidden;

Then you can use the original batch file:

del /s /f *.rej
del /s /f *.orig
...

Also you can avoid use of the batch file by directly executing the del command directly in the [Run] section:

[Run]
Filename: "{cmd}"; Parameters: "/C del /s /f *.rej"; WorkingDir: "{app}\res_mods"; \
    Flags: runhidden
Filename: "{cmd}"; Parameters: "/C del /s /f *.orig"; WorkingDir: "{app}\res_mods"; \
    Flags: runhidden
...

Though personally, as you rename the folder in [Code] section, I'd remove the files in code too. For a consistency.