5

We've recently had an application which installs using an INNO script undergo a significant restructuring.

Unfortunately the application requires certain files to persist from version to version.

Even more unfortunately, the location of these files has changed during this restructuring.

Most unfortunately, it now falls to me to craft an INNO script fragment which will look to see if those files exist, and to move them from their former location to their new location.

Is it possible to have an INNO script check to see if files (which have nothing to do with the INNO script itself in any capacity) exist, and if they do, to move them to a new location before/after the install is completed?

EDIT 1 : For Clarity

I say that these files have nothing to do with the INNO script because they are user-generated content.

Will
  • 3,413
  • 7
  • 50
  • 107
  • Possible duplicate of [How to rename a file using inno setup](http://stackoverflow.com/questions/13071129/how-to-rename-a-file-using-inno-setup) – Martin Prikryl Oct 23 '15 at 15:29

1 Answers1

5

Yes, it is possible. The code below is a copy and delete (instead of a raw move or rename).

Use the [Code] section to implement this logic.

The documentation about supported functions and the events you can handle is pretty good.

How to react on a beginning installation:

procedure CurStepChanged(CurStep: TSetupStep);
begin

  case CurStep of
    ssInstall:
    begin
      { will be executed just before the actual installation starts }
    end; 

   ssPostInstall:
    begin
      { will be executed just after the actual installation finishes }
    end; 
  end;

end;

How to know whether a file exists or not

if FileExists(FileName) then
begin
  { do something when the file exists }
end; 

Copy a file (overwrite exisiting file)

if not FileCopy(ExistingFileName, NewFileName: String, false) then
begin
  { handle copy error }
end;

Delete a file

if not DeleteFile(FileName) then
begin
  { handle delete error }
end;
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Wosi
  • 41,986
  • 17
  • 75
  • 82
  • 2
    To move a file use [`RenameFile` function](http://www.jrsoftware.org/ishelp/index.php?topic=isxfunc_renamefile) – Martin Prikryl Oct 23 '15 at 15:28
  • 1
    As far as I know `RenameFile` doesn't work when you want to move a file to a different drive – Wosi Oct 23 '15 at 15:34
  • Well, sure, because you cannot *move files to a different drive*. You have to copy to target drive and delete from source drive. – Martin Prikryl Oct 23 '15 at 15:38
  • For that reason I don't recommend to use `RenameFile` for moving files. It will sooner or later cause a bug e.g. when somebody installs the application on `D:` and the setup needs to move files from `%PROGRAMFILES%\OldInstallation` to the new installation folder. – Wosi Oct 23 '15 at 15:44
  • 2
    Copy and then delete isn't problem free either. You could be spending a long time doing something that could have been done instantly. Copy and delete also will use a lot of disk space, and if your drive space was low, might fail. – Warren P Jan 17 '18 at 19:38