Page 1 of 1

Rename a section or delete all the keys in INI file

Posted: Tue May 06, 2014 10:06 am
by samira
Hi , I have around 20 keys+values under one section in an INI file and trying to remove all the keys or rename the section at least so my server does not read this section any more.
I tried Reading all the ini file content via ReadAll from text and parse the strings and having a loop to edit ini file content using Line-> remove in a loop for that section each line . It reads all the line and I can get each key and value but at the end it just deletes one row and not all.
you can see below what I did:

===========================================================================================================================
Read from Text File #READALL\$TARGETDIR$\Server\SvrCnfg.ini into Variable FieldMapSettings (get EOF into Test)
Parse String $FieldMapSettings$ into Variables and FieldMapSettings1 (Split at first occurrence of pattern)
Parse String $FieldMapSettings1$ into Variables FieldMapSettings2 and (Split at first occurrence of pattern)
Parse String $FieldMapSettings2$ into Variables FieldMapSettingsEach and FieldMapSettingsRest (Split at first occurrence of pattern)
while Variable FieldMapSettingsEach not Equals loop
Parse String $FieldMapSettingsEach$ into Variables FieldMapSettingsKey and FieldMapSettingsValue (Split at first occurrence of pattern)
if Variable FieldMapSettingsKey not Equals
Edit INI File $TARGETDIR$\Server\SvrCnfg.ini, [FieldMap] $FieldMapSettingsKey$=$FieldMapSettingsValue$
end
Parse String $FieldMapSettingsRest$ into Variables FieldMapSettingsEach and FieldMapSettingsRest (Split at first occurrence of pattern)
wend

=================================================================================================================================
Anyone has any idea how to rename the section or remove all the keys?

Thanks
Samira

Re: Rename a section or delete all the keys in INI file

Posted: Tue May 06, 2014 10:53 am
by FrancescoT
Dear Shamira,

Are you sure that in your loop sequence, the "Edit INI" command is effectively executed for each entry you want to modify? Did you try to debug it?

Regards

Re: Rename a section or delete all the keys in INI file

Posted: Wed May 07, 2014 7:19 am
by samira
Yes, I added a message there and I can see it goes through all the lines but it just deleted one of the line at the end !

Re: Rename a section or delete all the keys in INI file

Posted: Wed May 07, 2014 7:21 am
by samira
Tried this as well but still the same:

for each Element EachLine in $NEWLINE$ delimited Collection of $FieldMapSettingsRest$ do
MessageBox: , EACH LOOP : $EachLine$
Parse String $EachLine$ into Variables FieldMapSettingsKey and FieldMapSettingsValue (Split at first occurrence of pattern)
if Variable FieldMapSettingsKey not Equals
MessageBox: , KEY: $FieldMapSettingsKey$
Edit INI File $TARGETDIR$\Server\SvrCnfg.ini, [FieldMap] $FieldMapSettingsKey$=$FieldMapSettingsValue$
MessageBox: , VALUE : $FieldMapSettingsValue$ is removed
end
next

Re: Rename a section or delete all the keys in INI file

Posted: Wed May 07, 2014 11:04 am
by FrancescoT
Dear Samira,

could you please post the same code as "InstallAware Clipboard Format" within a "Code tag" along with the ini file?

In this way I can try to debug it.

Regards

Re: Rename a section or delete all the keys in INI file

Posted: Mon May 12, 2014 5:13 am
by samira
~InstallAware Clipboard Data~
~MessageBox~
~{079496CF-81BC-4DD5-AAFD-7F3B9866E7EA}~
~~
~end of main loop~
~0~
~1~
~~
~Next~
~{B25804B6-2713-4F0E-BB6F-121BA56CBE1D}~
~MessageBox~
~{CB5FE7F0-C096-47C9-9E39-0445178EE6EC}~
~~
~end of nested loop~
~0~
~1~
~~
~Next~
~{6AA562D3-6772-4A00-82EC-F0FE42DAA87F}~
~End~
~{FD95F455-3B50-4BE0-9A52-3FCB1F5CB2C2}~
~MessageBox~
~{7023E687-D430-4EDB-9C6D-86F05FEF1A42}~
~~
~EACH Key : $EachKey$ is removed~
~0~
~1~
~~
~Edit INI File~
~{51AD4ED3-2D98-4E7A-A064-2B27B9D8A250}~
~$TARGETDIR$\Server~
~SvrCnfg.ini~
~2~
~FieldMap~
~$EachKey$~
~~
~If~
~{D5E42BAE-2772-4031-B602-BE717D7B04A1}~
~EachKey~
~1~
~JOB~
~TRUE~
~For Each~
~{7D90E15E-B5FE-4DD2-B623-BF194B1FCCFF}~
~EachKey~
~=~
~$EachLine$~
~For Each~
~{70DF04D4-1816-43A0-B1E7-D506DA9E3014}~
~EachLine~
~$NEWLINE$~
~$FieldMapSettings1$~
~Parse String~
~{DE47E7E8-88C3-414E-9568-C67BD3AC8124}~
~$FieldMapSettings1$~
~$NEWLINE$~
~FieldMapSettings2~
~~
~0~
~FALSE~
~FALSE~
~Parse String~
~{F27DADA9-A301-47CB-AAC0-1372EC0F8031}~
~$FieldMapSettings$~
~[FieldMap]~
~~
~FieldMapSettings1~
~0~
~FALSE~
~TRUE~
~Read from Text File~
~{A23BFA6F-C92B-47A6-84E1-31373BD25E97}~
~#READALL\$TARGETDIR$\Server\SvrCnfg.ini ~
~FieldMapSettings~
~Test~


and in the ini file I have this :


[FieldMap]
RESTASK.MANAGER=JOB.JOB_MANAGER
RESTASK.ID=JOB.JOB_ID
RESTASK.NAME=JOB.JOB_DESCR
RESTASK.PRIORITY=JOB.JOB_BKG_BTY_ID
RESTASK.ANALYSIS=JOB.JOB_CRD_ID

Re: Rename a section or delete all the keys in INI file

Posted: Mon May 12, 2014 11:21 am
by FrancescoT
Let me check.

Regards
Francesco

Re: Rename a section or delete all the keys in INI file

Posted: Tue May 13, 2014 6:28 am
by samira
Thanks a lot

Re: Rename a section or delete all the keys in INI file

Posted: Tue May 13, 2014 12:03 pm
by FrancescoT
Dear Samira,

Please have a look at the attached project.

The project stores the original INI file under SUPPORTDIR, copies it to C:\Mytest and then executes the ini entries removal.

NOTE!
The "Edit INI FILE" is a Windows Installer command (purple command) and due of this, its execution is deferred to Apply Install Execution.
With my sample I used NATIVE ENGINE to execute the command immediately.

Regards

Re: Rename a section or delete all the keys in INI file

Posted: Wed May 14, 2014 3:40 am
by samira
Dear FrancescoT

Thanks a lot. It works now :)

Re: Rename a section or delete all the keys in INI file

Posted: Wed May 14, 2014 10:46 am
by FrancescoT
Happy you solved!

Regards