问题
I'm making a setup script in Inno and I was wondering, how can I get non "hardcoded" path. Here is example:
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!
回答1:
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.
回答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
来源:https://stackoverflow.com/questions/25620729/inno-setup-how-to-get-dynamically-path-to-file