6
votes

How can we copy, move, rename user files before installation?

We can easily delete files using the [InstallDelete] section:

[InstallDelete]
Type: files; Name: "{app}\SomeFile.exe";

Can we do copy, rename in a similar way?

EDIT:

I tried to make this in [Files] section but I receive an error during compilation because source file does not exist:

[Files]
Source: "{app}\SomeFile.exe"; DestDir: "{app}\SomeDir\SomeFile.exe"; 
1
If the source file doesn't exist, how is InnoSetup supposed to include it in the installation? - Thorsten Dittmar
@Thorsten, you can use external flag, but it's a bad idea even if it would work. - TLama
@Thorsten: I do not want to include these file in installation. These are user]s save files that I want to move in other subdirectory of the application (if files exists). - Miroslav Popov
Yes, that's what I was talking about :-) The way you were trying it, the compiler expects the files to be present on your local harddrive to include them in the setup. - Thorsten Dittmar

1 Answers

8
votes

For copying files you can use the [Files] section, but I don't think there's a way for move or rename operations in a separate section, so I would suggest you to use [Code] section for this.

Here is a sample code for move and rename operations. They both use the RenameFile function as it is internally the same operation:

[Code]
procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssInstall then
  begin
    // move file
    if not RenameFile(ExpandConstant('{app}\SomeDir\SomeFile.exe'), ExpandConstant('{app}\SomeFile.exe')) then
      MsgBox('File moving failed!', mbError, MB_OK);
    // rename file
    if not RenameFile(ExpandConstant('{app}\SomeFile.exe'), ExpandConstant('{app}\RenamedSomeFile.exe')) then
      MsgBox('File moving failed!', mbError, MB_OK);
  end;
end;