Search code examples
parameter-passinginno-setuppascalscript

Inno Setup Prompt user for a folder and store the value


I have following need:

[Run] 
;run robocopy.exe source dest/OLD/[source_contents] /options

Where:
source must be specified by user on the destination machine (this can change according the physical platform)
destination will be identical to the just user-defined source folder while the subpath OLD/[source_contents] will be automatically created by the robocopy input.

I was thinking to use a "scripted-constant", but the problem is that I need to store some way the "source" prompted parameter some where (I cannot require two prompts for the same place).

Thanks.


Solution

  • The scripted constant is a way to go. You just need to make sure you prompt the user just once and reuse the results for both the source an the destination path.

    You can for example use CreateInputDirPage and implement the scripted constant to refer to a path that a user specified on the page:

    [Run]
    Filename: "robocopy.exe"; Parameters: "{code:CopyDir} {code:CopyDir}\OLD"
    
    [Code]
    var
      CopyDirPage: TInputDirWizardPage;
    
    procedure InitializeWizard();
    begin
      CopyDirPage :=
        CreateInputDirPage(wpSelectDir, 'Select source directory', '',  '', False, '');
      CopyDirPage.Add('Source directory:');
    end;
    
    function CopyDir(Params: string): string;
    begin
      Result := CopyDirPage.Values[0];
    end;