Deleting Portion of ini file

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
cyber_author
Newbie
Posts: 10
Joined: Sun Aug 07, 2005 10:42 am

Deleting Portion of ini file

Post by cyber_author » Fri Aug 26, 2005 10:02 am

What I am trying to do is allow someone to enter some values into my macro and save the configurations i.e. using an ini file to save and load various configurations for the user.

Example:

[fred] (fred is the config name in the combobox)
username=fred
useremail=[email protected]
[albert] (albert is the config name in the combobox)
username=albert
useremail=[email protected]

They get a screen, input the data and it saves it in the ini. I am using a combobox to let them go back and select the saved entry to load it. I have that all down and good... however...

If they want to remove [fred] from the ini file, how could I do that? Also, would like to have the label removed from the combobox too... ie. remove "fred"

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Sat Aug 27, 2005 4:56 am

You could use the "ReadLn" function to read each individual line of the INI file then use the "WriteLn" function to write each line to a new temporary file. When the line with the section header you're looking for comes up, stop writing until the next section header is read, then write the rest of the INI file to the temporary file. Then, just to be on the safe side rename the INI file to a backup file name or location. Then rename and/or move the temporary file to the INI file name and location.

Something like this:(untested)

Let>k=0
Label>start
Let>k=k+1
ReadLn>C:\path\file.ini,%k%,line
If>line=##EOF##,finish
If>line=[fred],stopwriting
Label>startwriting
WriteLn>C:\path\tempfile.tmp,wresult,%line%
goto>start

Label>stopwriting
Let>k=k+1
ReadLn>C:\path\file.ini,%k%,line
If>line=##EOF##,finish
Midstr>%line%,1,1,result
If>result=[,startwriting,stopwriting

Label>finish
MoveFile>C:\path\file.ini,C:\path\file.bak
MoveFile>C:\path\tempfile.tmp,C:\path\file.ini

Hope this helps,
Dick

cyber_author
Newbie
Posts: 10
Joined: Sun Aug 07, 2005 10:42 am

Post by cyber_author » Sat Aug 27, 2005 7:01 am

thanks! I will try that asap! didn't think of that, duh! looks like that should work.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts