Jump to content

read a unique ini


mud409
 Share

Recommended Posts

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

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

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!

Link to comment
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?

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...