INIFile.GetSectionNames

table INIFile.GetSectionNames ( 

string Filename )

Example 1

section_names = INIFile.GetSectionNames(_SourceFolder .. "\\settings.ini");

Gets all of the section names within the INI file named "settings.ini" and stores them in a table called "value_names."

Note: _SourceFolder is a built-in variable that contains the path to the folder where the setup.exe file is located.

Example 2

-- Get all of the section names in an INI file.
all_sections = INIFile.GetSectionNames("C:\\Data.ini");

-- Check to see if any error occurred.
error = Application.GetLastError();

-- If an error occurred, display the error message.
if (error ~= 0) then
    Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
else
    found = false;
    -- Check to see if any sections are present.
    if (all_sections ~= nil) then
        -- Go through each section and try to get a value.
        for index_section, section in pairs(all_sections) do
            -- Try to get the data of the value you want.
            value_data = INIFile.GetValue("C:\\Data.ini", section, "Path");

            -- If the value was found, modify it's data.
            if value_data ~= "" then
                INIFile.SetValue("C:\\Data.ini", section, "Path", _ProgramFilesFolder.."\\MyApplication");
              
                -- Check to see if any error occurred.
                error = Application.GetLastError();
                -- If an error occurred, display the error message.
                if (error ~= 0) then
                    Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
                end

                found = true;
                break;
            end
        end
    end

    -- If the value was not found.
    if (all_sections == nil) or (not found) then
        -- Create a new section with a new value and data.
        INIFile.SetValue("C:\\Data.ini", "INSTALL", "Path", _ProgramFilesFolder.."\\MyApplication");

        -- Check to see if any error occurred.
        error = Application.GetLastError();
        -- If an error occurred, display the error message.
        if (error ~= 0) then
            Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
        end
    end
end

The purpose of this example is to search for a particular value name in an INI file whose section name is unknown. If that value is found, it's data is updated. If it is not found, a new section, value and data is created in the file.

See also:  Related Actions