MSI Factory 2.3

INIFile.GetSectionNames

INIFile.GetSectionNames

This is the first topic This is the last topic  

INIFile.GetSectionNames

This is the first topic This is the last topic  

OverviewExamples

table INIFile.GetSectionNames (

string Filename )

Example 1

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

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

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 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", Shell.GetFolder(SHF_PROGRAMFILES).."\\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", Shell.GetFolder(SHF_PROGRAMFILES).."\\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


Learn More: Indigo Rose Software - MSI Factory - Buy Now - Contact Us