mIRC Homepage
Posted By: Joe_Dean Another INI Inquiry - 14/10/08 07:08 PM
I love working with INI's. laugh

How would I search through every INI in the specified directory and return the value of the specified item in each INI? Example:

Quote:
Files in the directory \INI\:
1.ini
2.ini
3.ini
etc.


Quote:
Each INI file in this directory contain this:
blah=something


Quote:
If this on TEXT event happens:
Joe: !searchini
..I want it to return the values of 'blah=' in each INI...


Posted By: Horstl Re: Another INI Inquiry - 14/10/08 07:16 PM
The data stored at ini files is allocated in one or more [sections]. Do sections really don't play a role in this question? Just an enquiry, because - maybe - you might use different sections of one ini file (instead of multiple inis) to store your data anyway smile
Posted By: Joe_Dean Re: Another INI Inquiry - 14/10/08 07:36 PM
No, all INI files contain exactly this:

Code:
[settings]
name=


The only difference between each INI is the value of 'name='.
Posted By: Horstl Re: Another INI Inquiry - 14/10/08 09:50 PM
Ok. This is easier than the script here , but you might identify the similar structure:

1) An on text event for the !trigger. Here further flood protection/a restricted access to the trigger etc might be added.

2) Now it scans for all (matching on *.ini) files of a specific directory. A command, (in this case: "searchini") is performed on each matching file.

3) This searchini-command (an alias) does the actual in-file search, this time it's a $readini command (the other script used /filter). The result ("matches") of each in-file search is written to a temporary file. All the results thus sum up in this temporary file (and you can format the desired output here).

4) After all the files had been processed by the command, it will check if there had been any matches (=is there a tempfile?). If this is true, the tempfile is "played" to the channel (which is a good way to prevent message flood, and in fact that's why I used a temp-file at all smile ). The tempfile can now be removed.

Code:
on *:text:!searchini:#YOURCHANNEL: {
  var %dir = $mircdir $+ ini
  noop $findfile(%dir,*.ini,0,searchini $1-)
  if ($isfile(searchiniresults.txt)) {
    .play -q5m3 $chan searchiniresults.txt 500
    .remove searchiniresults.txt
  }
}

alias -l searchini {
  if ($readini($1-,settings,name)) {
    write searchiniresults.txt INI: $nopath($1-) VALUE: $v1
  }
}

Posted By: DJ_Sol Re: Another INI Inquiry - 15/10/08 12:31 PM
Thats a cool way of doing it. I do it the noob way I guess.

Use $ini to find out how many items are in the section, how many sections in the file. Etc. Then just use a while loop to run through each one.


Code:
var %xx = $ini(file.ini,section,0)
while (%xx) { msg $chan $readini(file.ini,section,$ini(file.ini,section,%xx)) }
dec %xx
}
© mIRC Discussion Forums