jgg Posted March 28, 2004 Share Posted March 28, 2004 (edited) I have a ini-file which i want to change [Global] ;direct ;AccessType=17 ;modem ;AccessType=0 disconnect=1 AccessType=17 In the section Global i have two lines commented, i don't want these to change, but i want the last name in the ini-file to change to AccessType=0. After some hour i want to change the ini-file to AccessType=17. I have tried with IniWrite, but then the row come at the bottom, not in the beginning where it is. Anyone having a solution??? Edited March 28, 2004 by jgg Link to comment Share on other sites More sharing options...
Administrators Jon Posted March 28, 2004 Administrators Share Posted March 28, 2004 I don't think that an ini file with a comment in it is a valid "proper" ini file - it's just a file that looks ini-ish. What happens if you also try and delete the key called ";AccessType" with IniDelete? Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/ Link to comment Share on other sites More sharing options...
jgg Posted March 28, 2004 Author Share Posted March 28, 2004 No, inidelete doesn't delete ;AccessType=17 Hmm.. Link to comment Share on other sites More sharing options...
jgg Posted March 29, 2004 Author Share Posted March 29, 2004 Is there any other way to update the ini-file without using iniwrite, eg reading file for Accesstype=17, changing to Accesstype=0, rewrite post, close file ?? Thanks... Link to comment Share on other sites More sharing options...
scriptkitty Posted March 29, 2004 Share Posted March 29, 2004 Why not just not overwrite it, say: [Global] direct=1 AccessTypedefault=17 modem=1 AccessTypeZero=0 disconnect=1 AccessType=17 How are you using the INI? You could always just yse a text file to store data, or use it only has a text file: [Global] ;direct ;AccessType=17 ;modem ;AccessType=0 disconnect=1 AccessType=17 To access line 7, use $AccessType=StringSplit(FileReadLine("ini-file",7) ,"=") $accessType[2] will be 17, $accessType[1]="AccessType" InI files work great as InI files, I am not sure why you have the comments in them, could you use a comment section? [Global] disconnect=1 AccessType=17 [comments] ;direct ;AccessType=17 ;modem ;AccessType=0 AutoIt3, the MACGYVER Pocket Knife for computers. Link to comment Share on other sites More sharing options...
Holger Posted March 29, 2004 Share Posted March 29, 2004 (edited) Hey jgg, where is the problem? If I use: IniWrite("test.ini","Global","AccessType","0") the test.ini looks like: [Global] ;direct ;AccessType=17 ;modem ;AccessType=0 disconnect=1 AccessType=0 So I don't see any problem here... Or did I missunderstand something? What did you mean with?: I have tried with IniWrite, but then the row come at the bottom, not in the beginning where it is.Holger Edited March 29, 2004 by Holger Old project:GUI/Tray menu with icons and colors Other old stuff:IconFileScanner, TriState/ThreeState GUI TreeView, GUI ContextMenu created out of a TreeView Link to comment Share on other sites More sharing options...
jgg Posted March 30, 2004 Author Share Posted March 30, 2004 Thanks everybody... Holger - i tried your solution - doesn't work because the ini-file isn't a regular ini-file it seems according to jon. It's not a microsoft-program, i think the programmer who did it has made an own sort of ini-file. Scriptkitty, i will try your solution.. Link to comment Share on other sites More sharing options...
scriptkitty Posted March 30, 2004 Share Posted March 30, 2004 (edited) Well here is more of the solution, hope it is easy to understand. final one you would want to replace the actual ini with the tempfile. expandcollapse popup$inifile="some.ini" $line_array=read($inifile) ;find AccessType=17 $num=finder1($line_array,"AccessType") $key=Stringsplit($line_array[$num],"=") msgbox(1,$key[1],$key[2]); show you the key and value ;now to change it. replaceit($inifile,$line_array,$key[1]&"="&"2",$num) func read($inifile) $lines=FileRead($inifile,FileGetSize($inifile)) $lines=Stringreplace($lines,@lf,""); to make @cr & @lf to @cr for good split $x=Stringsplit($lines,@cr) return $x endfunc func finder1($array,$find) for $i=1 to $array[0] $y=Stringsplit($array[$i],"=") if isarray($y) then if $y[1]=$find then return $i endif next endfunc func replaceit($file,$array,$value,$linenumber) for $i=1 to $array[0] if $i=$linenumber then filewriteline("my_tempfile.ini",$value) else FileWriteLine("my_tempfile.ini",$array[$i]) endif next endfunc Edited March 30, 2004 by scriptkitty AutoIt3, the MACGYVER Pocket Knife for computers. 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