Sign in to follow this  
Followers 0
mud409

read a unique ini

6 posts in this topic

I'm having troubles reading and writing to an ini with a layout that looks like the following

#
# Section
#
known_key_audit           2
unknown_key_audit         2

The empty space between key and value is 26 characters minus the length of key name. I will have the exact name for some keys, however some I will only have the first few letters, and _key_audit, there will be a section in between that is random like key$unknownvariable_key_audit

Any suggestions are appreciated, as I'm stumped, and need to get this finished quick, like a :nuke: but I am :shifty: and not :lol: enough :( I need more :x 'til then :P I need heeeeeelllllp, and maybe a hug from a smiley face. Okay, I'll stop talking in smilies now. :D oops

Share this post


Link to post
Share on other sites



What do you exactly mean by "... I'm having troubles reading and writing to an ini ..."?

Let's start with the reading part.

What do you want to do? Get all records with "_key_audit"? Only get some of them?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

mud409,

The normal Ini* functions are useless here :P - so you will have to read the file into an array using _FileReadToArray.

Then to read a value:- Use _ArraySearch to find the line you want - and then StringMid to get the value from the 27th character onwards.

And to write a value:- Use _ArrayInsert to get the value into the correct place in the array and then rewrite the ini using _FileWriteFromArray.

Give it a go - it is not that difficult - and you know where we are if you need help. :x

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Hi.

Your examle is syntactically *NOT* an INI file.

[section1]
name1=value1
name2=value2
[section2]
name3=value4
...

So, as already mentioned, use _filereadtoarray() to read the full file into an array.

Then kick the comments.

Then split the valid lines to prefix and the rest, kick WhiteSpaces

#include <file.au3> ; for _filereadtoarray()
#include <array.au3> ; for _arraydisplay() and _arraydelete()

$File="C:\sample.txt"
$MyArr=""
$Comment="#"
$PreLen=26 ; how long is the left part?

_FileReadToArray($File,$MyArr)

_ArrayDisplay($MyArr)

for $i = $MyArr[0] to 1 step -1
    if StringLeft($MyArr[$i],1)=$Comment then _ArrayDelete($MyArr,$i)
Next

$MyArr[0]=UBound($MyArr)-1

_ArrayDisplay($MyArr)

for $i = 1 to $MyArr[0]
    $left=StringLeft($MyArr[$i],$PreLen)
    $left=StringStripWS($left,1+2) ;remove leading and trailing whitespaces
    $right=StringTrimLeft($MyArr[$i],$PreLen)
    ; do want you need with $left and right here
    ;...
Next

Regards, rudi.

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

I completely forgot about posting this. Thanks for the input, and your script works great for small files, Rudi.

Unfortunately this really isn't possible in AutoIt, because the "ini" is 55 thousand lines. Reading the ini takes ridiculously long, and I need to rewrite a lot of those values. AutoIt can't write to a specific line number can it?

Share this post


Link to post
Share on other sites

mud409,

It is likely that the thing taking so much time in rudi's script is the _ArrayDisplay line - it is a very slow function, especially if you are looking at 55k lines. :shifty:

AutoIt can't write to a specific line number can it?

Did you think to look in the Help file? Probably not, or the _FileWriteToLine function might have given you the answer. :P Besides if you have the file nicely read into an array, you merely need replace the array element rather than rewrite the file directly.

So I would suggest again that it perfectly possible to do what you want in AutoIt, using the commands I mentioned in my post above. Why not try and see if you can get something working? You know where we are if you need help on some specific details. :x

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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