Sign in to follow this  
Followers 0
Berti

How to insert sections in ini-files?

6 posts in this topic

Hi,

I've a lot of different textfiles, which looks like ini-file. (main.cfg). In this main.cfgs are a lot of sections ([sectionA.0], [section A.1], ..., [sectionB.0] and so on). Each main.cfg has one ore more A-sections.

I want to add one ore more (up to 10) new A-sections after the last A-section in the main.cfg. The new A-sections should contain the same keys (with different values of course) as the existing A-section.

So I think I've to count the A-sections first (should be no problem). But what to do then? Copy and rename the last A-section (I don't know how)? Create a new A-section? How can I insert the keys then?

Or is it better (easier) to create a second file with the A-sections prepared to insert? Nevertheless, they must be renamed because I don't know how many A-sections are in the main.cfg.

Thnx for help

Berti

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

just use this format

IniWrite ( "filename", "section", "key", "value" )

and it will create the new section name and place the value that you want

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

Look at the help files.....

Writes a value to a standard format .ini file.

IniWrite ( "filename", "section", "key", "value" )

Parameters:

filename The filename of the .ini file.

section The section name in the .ini file.

key The key name in the in the .ini file.

value The value to write/change.


AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

Oh, I know the IniWrite command. One of the problems is to create a new section b e t w e e n two other sections and not at the end of the file.

Berti

Share this post


Link to post
Share on other sites

What different it make if IniWrite create the section at the end when you have:

Reads a value from a standard format .ini file.

IniRead ( "filename", "section", "key", "default" )

That will read the key not matter where the section is located....


AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

If you had to absolutely have it in order...you could just get the section names, pull an _ArraySort() and then rewrite the file


Writing AutoIt scripts since
_DateAdd("d", -2, _NowCalcDate())

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0