Spartanicus Posted June 7, 2007 Posted June 7, 2007 (edited) I need to add a key to an INI file section, but without a "=" or a value. This means that I can't use the "IniWrite" function (which if I null the value still appends the "="). Can anyone point me to an example script from which I could learn how to insert a line under a "[Header]" in a text file? (not append at the end of the file) Edited June 7, 2007 by Spartanicus
Xenobiologist Posted June 7, 2007 Posted June 7, 2007 Hi, _FileWriteToLine or _FileReadToArray insert _FileWriteFromArray So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
Spartanicus Posted June 7, 2007 Author Posted June 7, 2007 th.meger said: _FileWriteToLine or _FileReadToArray insert _FileWriteFromArrayBeginner here, I've no idea what that means.
Xenobiologist Posted June 7, 2007 Posted June 7, 2007 Hi, that are function names. Have a look at the examples in the great helpfile. So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
Spartanicus Posted June 7, 2007 Author Posted June 7, 2007 th.meger said: that are function names. Have a look at the examples in the great helpfile.Already did that.I can only find a "FileWriteLine" function (note no preceeding underscore and no "To"), and "FileWriteLine" afaics can only append a line to the end of the file. As I noted in my OP this isn't what I need, I need to insert a line somewhere before the end of the file.As for "_FileReadToArray" and "_FileWriteFromArray" a search through the help file came up blank, same if I ommit the underscore.
Xenobiologist Posted June 7, 2007 Posted June 7, 2007 Hi, okay I'll help you. Do you want to insert a line as line 2 or after a specific text or line ow what? So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
Spartanicus Posted June 7, 2007 Author Posted June 7, 2007 th.meger said: Do you want to insert a line as line 2 or after a specific text or line ow what? As per the OP I need to insert a line below a header in an INI file, structure is something like this: [header1] foo bar text to be added [header2] blah=foo boo=bar The position of "[header1]" or its content isn't fixed.
Xenobiologist Posted June 7, 2007 Posted June 7, 2007 (edited) HI, #include<Array.au3> #include<File.au3> _insertLineToFile(@ScriptDir & '\test.ini', '[24324]', 'test') Func _insertLineToFile($filePath, $after, $insertText) Local $lines If Not _FileReadToArray($filePath, $lines) Then Return -1 _ArrayInsert($lines, _ArraySearch($lines, $after, 1, 0, 0) + 1, $insertText) If _FileWriteFromArray($filePath, $lines, 1) Then Return 1 Return -2 EndFunc ;==>_insertLineToFile So long, Mega Edited June 7, 2007 by th.meger Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
ResNullius Posted June 7, 2007 Posted June 7, 2007 Spartanicus said: As for "_FileReadToArray" and "_FileWriteFromArray" a search through the help file came up blank, same if I ommit the underscore.These are User "Defined Functions" that are installed in the "Include" folder. For the help file, open "UDFs3.chm" in you main AutoIt3 installation folder.
Spartanicus Posted June 7, 2007 Author Posted June 7, 2007 ResNullius said: These are User "Defined Functions" that are installed in the "Include" folder. For the help file, open "UDFs3.chm" in you main AutoIt3 installation folder.Ah! Apologies to Mega for not getting that, I hadn't spotted the UDF's and their help file yet, reading up on them now.
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