inno-setuppascalscript

Read contents of a file from within Inno Setup installer


I am using Inno Setup. I read from file with

LoadStringsFromFile(My_file, Lines)

but the file is outside installation file defined with

OutputBaseFilename={#MySetupExeName}

Can I open a file inside iss code, and this file to be in installation file (OutputBaseFilename)?


Solution

  • Use ExtractTemporaryFile:

    [Files]
    Source: myfile.txt; Flags: dontcopy
    
    [Code]
    ...
    ExtractTemporaryFile('myfile.txt');
    LoadStringsFromFile(ExpandConstant('{tmp}\myfile.txt'), Lines);
    ...
    

    Though as the contents is fixed, you can as well hard-code it.

    Or read it from the file on compile-time, instead of having to extract the file on install-time. You can use preprocessor FileRead function for that. Though it's more complicated than the straightforward code above. We would have to know more about that you need the contents for and how it looks like to offer an efficient solution.