Sign in to follow this  
Followers 0
jgg

Ini-file Change

8 posts in this topic

#1 ·  Posted (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 by jgg

Share this post


Link to post
Share on other sites



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?

Share this post


Link to post
Share on other sites

No, inidelete doesn't delete ;AccessType=17

Hmm..

Share this post


Link to post
Share on other sites

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...

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 by Holger

Share this post


Link to post
Share on other sites

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..

Share this post


Link to post
Share on other sites

#8 ·  Posted (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.

$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 by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

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