mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: May 2008
Posts: 127
J
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.
Joined: Aug 2003
Posts: 144
M
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

Joined: May 2008
Posts: 127
J
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.

Joined: Dec 2002
Posts: 2,962
S
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.
Joined: May 2008
Posts: 127
J
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

Joined: Dec 2002
Posts: 2,962
S
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.
Joined: May 2008
Posts: 127
J
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.
Joined: Dec 2002
Posts: 2,962
S
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.

Link Copied to Clipboard