Inno Setup (How to get dynamically path to file)?
Asked Answered
F

2

13

I'm making a setup script in Inno and I was wondering, how can I get non "hardcoded" path. Here is example:

Image, which contains patch source

Thanks in advance!

SOLUTION:

You can get .iss folder by using predefined variable

SourcePath

Usage would be like: {#SourcePath}\???\bin\x86\Release\???.exe

Thanks all who contributed!

Flavour answered 2/9, 2014 at 10:1 Comment(5)
#define MyAppName "MY APP" #define MyAppExeName "my_app.exe" [Files] Source: "{userdesktop}\{#MyAppName}\SOURCES.PROJECTS\???\???\Release\{#MyAppExeName}"Whatley
@Whatley if I run this script from other computer and lets say that the folder is not on Desktop, this would not work right?Flavour
{userdesktop} constant always points the real desktop of current user - no matter what language version of Windows is installed. In Polish it would be e.g. C:\Użytkownicy\MOJ_PROFIL\PulpitWhatley
Yes I understand that @RobeN. Now I'm asking you, how to get a script folder. Lets say that my install script (.iss -> script) is located in Desktop/SOURCES.PROJECTS/???/InstallScript.iss. Now I want to achieve "Desktop/SOURCES.PROJECTS/???/". I found one solution here already, but its not working for me. Thanks btw.Flavour
There's no need for preprocessor variable here. You can use relative paths.Germaine
G
20

The reference about the source directory says (emphasized by me):

By default, the Setup Compiler expects to find files referenced in the script's [Files] section Source parameters, and files referenced in the [Setup] section, under the same directory the script file is located if they do not contain fully qualified pathnames. To specify a different source directory, create a SourceDir directive in the script's [Setup] section.

This includes also option to specify relative path to the files. So let's assume that you have the following file structure and you didn't specify a different path in the SourceDir directive:

C:\Deploy\Script.iss
C:\Deploy\MyProg.exe
C:\Deploy\SubFolder\MyOtherProg.exe
C:\Folder\SomeFile.txt

Now if you'd like to include the MyProg.exe into the setup compiled from the Script.iss script, you could specify just the file name without the path, since the MyProg.exe file is stored in the same folder as the script, so you could write just:

[Files]
Source: "MyProg.exe"; DestDir: "{app}"

And you can use a relative path to the MyOtherProg.exe which is stored in the subfolder of the folder where the Script.iss script is stored this way:

[Files]
Source: "SubFolder\MyOtherProg.exe"; DestDir: "{app}"

As well as you can use a relative path to include the SomeFile.txt stored in a subfolder of the parent folder where the script is stored:

[Files]
Source: "..\Folder\SomeFile.txt"; DestDir: "{app}"

More about relative path conventions you can read in this chapter.

Germaine answered 2/9, 2014 at 11:13 Comment(0)
C
2

Like OP has said in his own question,

You can get .iss folder by using predefined variable

SourcePath

Usage would be like: {#SourcePath}\???\bin\x86\Release\???.exe

Castlereagh answered 13/7, 2019 at 13:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.