Method RemoveOption don't work ?
Hi, I'm trying to use the method RemoveOption (and removeOptionByIndex) on one of my ini files, but it didn't seem to work
This is what my code (VBS) looks like:
function clear_watchdog INI_PATH = C:\xxx\xxx\variables.ini for i = 0 to Storages.INI(INI_PATH).GetSubSection("VARIABLES").OptionCount-1 OptionName = Storages.INI(INI_PATH).GetSubSection("VARIABLES").GetOptionName(i) if InStr(OptionName,"MEM_USAGE_STARTUP") <> 0 then Storages.INI(INI_PATH).GetSubSection("VARIABLES").RemoveOption(OptionName) end if next
Storages.INI(INI_PATH).Save
End Function
And there is an extract of my .ini file :
[VARIABLES] D_START=09/05/18 H_START=10:09:34 BDD_TYPE=SQL TEST_EXECUTION_ID=XXXXXX RunTheProject=true D_DEBUT=16/05/18 H_DEBUT=17:10:50 MS_XXX_13268_MEM_USAGE_STARTUP=75185 MS_XXX_10804_MEM_USAGE_STARTUP=88404 MS_XXX_6520_MEM_USAGE_STARTUP=24888 MS_XXX_13396_MEM_USAGE_STARTUP=20056
[Root]
Basicly everything works fine, but when my code goes to the line
"Storages.INI(INI_PATH).GetSubSection("VARIABLES").RemoveOption(OptionName) " it execute it (Or at least dont log any errors), but my .ini file still contain the option it was supposed to delete...
I've tried with RemoveOption and RemoveOptionByIndex, still nothing.
How do I do to remove thoses options ?
Thanks
I'm not sure... but I think it might have to do with you referencing the INI file as "Storages.INI(INI_PATH)" throughout the code rather than assigning the particular object. I'm not a VBSCript guy but what happens if your change your code like so:
function clear_watchdog INI_PATH = C:\xxx\xxx\variables.ini INIFile = Storages.INI(INI_PATH) for i = 0 to INIFile.GetSubSection("VARIABLES").OptionCount-1 OptionName = INIFile.GetSubSection("VARIABLES").GetOptionName(i) if InStr(OptionName,"MEM_USAGE_STARTUP") <> 0 then INIFile.GetSubSection("VARIABLES").RemoveOption(OptionName) end if next INIFile.Save End Function