mIRC Home    About    Download    Register    News    Help

Print Thread
Returning total number of INI's that contain item #201547 30/06/08 04:15 PM
Joined: May 2008
Posts: 127
J
Joe_Dean Offline OP
Vogon poet
OP Offline
Vogon poet
J
Joined: May 2008
Posts: 127
Is there a way I could return the number of INI files in the specified directory, but only the ones that have the specified text inside them?

$findfile(ini,*.ini,0)
This returns the total number of files in the /ini/ directory, but how do I include some matchtext and make the script only return the number of files that contain the matchtext?

Last edited by Joe_Dean; 30/06/08 04:15 PM.
Re: Returning total number of INI's that contain i [Re: Joe_Dean] #201552 30/06/08 04:33 PM
Joined: Aug 2003
Posts: 144
M
Miguel_A Offline
Vogon poet
Offline
Vogon poet
M
Joined: Aug 2003
Posts: 144
yes you can...

You need only to substitute the * for the correct match text.

example:.
$findfile($mircdir,*ir*.ini,0)

good luck

Re: Returning total number of INI's that contain i [Re: Miguel_A] #201560 30/06/08 06:09 PM
Joined: May 2008
Posts: 127
J
Joe_Dean Offline OP
Vogon poet
OP Offline
Vogon poet
J
Joined: May 2008
Posts: 127
Originally Posted By: Miguel_A
yes you can...

You need only to substitute the * for the correct match text.

example:.
$findfile($mircdir,*ir*.ini,0)

good luck


No, that only returns the number of files with the name "*irc*.ini". What I'm asking is, how do you search inside the INI files for the matchtext, and if it matches, return the number of INI files that contain that matchtext.

Re: Returning total number of INI's that contain i [Re: Joe_Dean] #201561 30/06/08 06:13 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
You would have to loop through $findfile() and then use $ini() or $readini() depending on whether the text you're searching for is a section name, item name, or item value.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: Returning total number of INI's that contain i [Re: starbucks_mafia] #201562 30/06/08 06:18 PM
Joined: May 2008
Posts: 127
J
Joe_Dean Offline OP
Vogon poet
OP Offline
Vogon poet
J
Joined: May 2008
Posts: 127
Originally Posted By: starbucks_mafia
You would have to loop through $findfile() and then use $ini() or $readini() depending on whether the text you're searching for is a section name, item name, or item value.


Could you give me an example? I'm the worst with loops :P

Re: Returning total number of INI's that contain i [Re: Joe_Dean] #201571 30/06/08 09:10 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Actually $findfile() has an internal loop mechanism available, so you can use that. For example:

Code:
alias count_ini_matches {
  var %dir = $1
  set -u %ini_matches_count 0
  noop $findfile(%dir, *.ini, 0, 0, checkini $1-)
  return %ini_matches_count
}

alias checkini {
  ; $1- holds the filename to check
  if (YOUR CHECK HERE) {
    inc %ini_matches_count
  }
}


You'd use $count_ini_matches(dirname) to get the count of matching INI files in that directory The /checkini alias is called once for each INI file in the directory with the filename as $1-. I still don't know what you're checking for so I couldn't fill in that bit but you just need to fill in the if condition.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: Returning total number of INI's that contain i [Re: starbucks_mafia] #201625 01/07/08 03:41 PM
Joined: May 2008
Posts: 127
J
Joe_Dean Offline OP
Vogon poet
OP Offline
Vogon poet
J
Joined: May 2008
Posts: 127
Ok, not sure what to put for the IF statement. I would imagine I'd use $ini, but not sure how I would use that correctly.

alias checkini {
; $1- holds the filename to check
if ($ini(*.ini,help) == 1) {
inc %ini_matches_count
}
}

Basically this looks for any INI file that contains the item "help=1", but I don't know what to put for *.ini...

Last edited by Joe_Dean; 01/07/08 03:42 PM.
Re: Returning total number of INI's that contain i [Re: Joe_Dean] #201699 02/07/08 04:05 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Like the comment in the code says, $1- will contain the the INI filename each time it's called. You won't be able to search for help=1 using $ini() though, to do that you'd use $readini() but you need to specify a section. INI files are in the format:

Code:
[firstsection]
key=value
anotherkey=anothervalue

[anothersection]
somekey=blah


So, what section is the help=1 supposed to be in within the INI file? Or can it be in any section within each file?

Assuming there is a specific section then use this:

Code:
alias checkini {
  ; $1- holds the filename to check
  if ($readini($1-, SECTION HERE, help) == 1) {
    inc %ini_matches_count
  }
}

Just change SECTION NAME to the relevant section name.

If it can appear in any section then you have to cheat and use $read() instead of a proper INI identifier:
Code:
alias checkini {
  ; $1- holds the filename to check
  if ($read($1-, wnt, help=1)) {
    inc %ini_matches_count
  }
}


Spelling mistakes, grammatical errors, and stupid comments are intentional.