Delete a section in an ini-file
Moderators: JRL, Dorian (MJT support)
Delete a section in an ini-file
How can I delete a complete section in an ini-file?
I'm sure there are other ways.
Be sure to make the value of the variable "file1" the full path and file name of the ini file.
The value of the variable "SectionName" will be case sensitive and must match the section name to be deleted exactly.
Be sure to make the value of the variable "file1" the full path and file name of the ini file.
The value of the variable "SectionName" will be case sensitive and must match the section name to be deleted exactly.
Code: Select all
Let>file1=IniFileToBeEdited
Let>SectionName=SectionNameToBeDeleted
ReadFile>File1,data
Separate>data,[,var
Let>kk=1
Let>newdata=
Repeat>kk
add>kk,1
Let>value=var_%kk%
Separate>value,],test
If>%test_1%=%SectionName%
Else
Let>newdata=%newdata%[%value%
EndIf
Until>kk,%var_count%
Deletefile>file1
Let>WLN_NOCRLF=1
WriteLn>file1,wres,newdata
Last edited by JRL on Tue Jul 14, 2009 12:57 pm, edited 1 time in total.
Code: Select all
I do not want the section name to be deleted, but the whole section including all entries.
Invent an ini file, call it C:\JRLtest.ini. Paste in the following:
Code: Select all
[Section1]
item1=1
item2=2
[Section2]
item1=1
item2=2
[Section3]
item1=1
item2=2
[Section4]
item1=1
item2=2
Code: Select all
[Section1]
item1=1
item2=2
[Section3]
item1=1
item2=2
[Section4]
item1=1
item2=2
I apologize for an error in the script as originally posted. I left my test data in the text. It has now been removed.