mud409 Posted December 12, 2010 Share Posted December 12, 2010 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 but I am and not enough I need more 'til then I need heeeeeelllllp, and maybe a hug from a smiley face. Okay, I'll stop talking in smilies now. oops Link to comment Share on other sites More sharing options...
water Posted December 12, 2010 Share Posted December 12, 2010 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 - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 12, 2010 Moderators Share Posted December 12, 2010 mud409,The normal Ini* functions are useless here - 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. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
rudi Posted December 13, 2010 Share Posted December 13, 2010 (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 December 13, 2010 by rudi Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
mud409 Posted December 15, 2010 Author Share Posted December 15, 2010 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 More sharing options...
Moderators Melba23 Posted December 15, 2010 Moderators Share Posted December 15, 2010 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. 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. 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. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now