Inno Setup (How to get dynamically path to file)?

Deadly 提交于 2020-01-13 08:59:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!