Is there a function or preprocessor directive that can be used to add multiple lines to the Files section in Inno Setup? For example, I have numerous occurrences of a pattern similar to the following:
[Files]
Source: "{#SrcPath}\Dir1\FileName.*"; DestDir: {#DstPath}\Dir1;
Source: "{#SrcPath}\Dir2\FileName.*"; DestDir: {#DstPath}\Dir2;
Source: "{#SrcPath}\Dir3\FileName\*"; DestDir: {#DstPath}\Dir3\FileName; Flags: recursesubdirs
And while I can just copy and paste the lines for each one, I was wondering if instead I could do something like this?
[Files]
AddFiles(FileName)
Unfortunately, I can't find any examples in the docs or online that illustrates how to do this. Is this possible?
Define a preprocessor macro (template) using the #define
directive like this:
#define FileTemplate(str FileName) \
"Source: """ + SrcPath + "\Dir1\" + FileName + ".*""; DestDir: " + DstPath + "\Dir1;" + NewLine + \
"Source: """ + SrcPath + "\Dir2\" + FileName + ".*""; DestDir: " + DstPath + "\Dir2;" + NewLine + \
"Source: """ + SrcPath + "\Dir3\" + FileName + ".*""; DestDir: " + DstPath + "\Dir3; Flags: recursesubdirs"
And expand the template using the #emit
directive like this:
#define SrcPath "C:\srcpath"
#define DstPath "{app}"
[Files]
#emit FileTemplate("FileName1")
#emit FileTemplate("FileName2")
If you get the preprocessor to dump a preprocessed file, you will see that the code produces this:
[Files]
Source: "C:\srcpath\Dir1\FileName1.*"; DestDir: {app}\Dir1;
Source: "C:\srcpath\Dir2\FileName1.*"; DestDir: {app}\Dir2;
Source: "C:\srcpath\Dir3\FileName1.*"; DestDir: {app}\Dir3; Flags: recursesubdirs
Source: "C:\srcpath\Dir1\FileName2.*"; DestDir: {app}\Dir1;
Source: "C:\srcpath\Dir2\FileName2.*"; DestDir: {app}\Dir2;
Source: "C:\srcpath\Dir3\FileName2.*"; DestDir: {app}\Dir3; Flags: recursesubdirs
For NewLine
predefined preprocessor variable, you need Inno Setup 6. See also Emit new line in Inno Setup preprocessor.