Remini

From Scriptwiki
Revision as of 12:59, 29 June 2007 by Cail (talk | contribs) (yeat another see also ...)

Jump to: navigation, search

Deletes whole sections or single items in an INI file.

/remini <inifile> <section> [item]

Example

remini user.ini address Dana

That example would delete the item called "Dana" in the section "address" in your user.ini.

remini user.ini $ini(user.ini,1)

This one deletes the first section in your user.ini

The next, complex example shows howto delete all items with a certain value:

; Let's have a new alias called "deletevalue". At the end, we want to have something like
; /deletevalue <inifile> <section|all> <value>
alias deletevalue { 
 ; if we have no 3 parameters, return
 if (!$3) { return }
 ; if $2 is all, we want to loop through the entire ini
 if ($2 == all) {
  var %i = 1
  ; we begin to loop through all sections
  while (%i <= $ini($1,0)) {
   var %j = 1 
   ; we begin to loop through all items in the current section
   while (%j <= $ini($1,%i,0)) {
    ; if the value of the current item is $3
    if ($readini($1,$ini($1,%i),$ini($1,%i,%j)) == $3) {
     ; we delete this item
     remini $1 $ini($1,%i) $ini($1,$ini($1,%i),%j)
    }
    ; if it is not, we want to go to the next item. If we've just deleted one item, we dont
    ; need to increase %j, as it is automatically a new item
    else {
     ; increase %j to go to the next item
     inc %j
    }
   }
   ; increase %i to go to the next sections as we are ready with this one
   inc %i
  }
 }
 ; if we only want to check one special section ($2 != all)
 else {
  var %j = 1
  ; lets loop through all items of this section
  while (%j <= $ini($1,$2,0)) {
   ; check if the value of the current item is $3
   if ($readini($1,$2,$ini($1,$2,%j)) == $3) {
    ; if it is, delete it
    remini $1 $2 $ini($1,$2,%j)
   }
   ; if not, increase the looping value
   else {
    inc %j
   }
  }
 } 
}

See Also