mIRC Home    About    Download    Register    News    Help

Topic Options
#201547 - 30/06/08 05:15 PM Returning total number of INI's that contain item
Joe_Dean Offline
Vogon poet

Registered: 04/05/08
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?


Edited by Joe_Dean (30/06/08 05:15 PM)

Top
#201552 - 30/06/08 05:33 PM Re: Returning total number of INI's that contain i [Re: Joe_Dean]
Miguel_A Offline
Vogon poet

Registered: 31/08/03
Posts: 143
Loc: Portugal - Figueira Da Foz
yes you can...

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

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

good luck

Top
#201560 - 30/06/08 07:09 PM Re: Returning total number of INI's that contain i [Re: Miguel_A]
Joe_Dean Offline
Vogon poet

Registered: 04/05/08
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.

Top
#201561 - 30/06/08 07:13 PM Re: Returning total number of INI's that contain i [Re: Joe_Dean]
starbucks_mafia Offline
Hoopy frood

Registered: 09/12/02
Posts: 2962
Loc: Norwich, UK
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.

Top
#201562 - 30/06/08 07:18 PM Re: Returning total number of INI's that contain i [Re: starbucks_mafia]
Joe_Dean Offline
Vogon poet

Registered: 04/05/08
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

Top
#201571 - 30/06/08 10:10 PM Re: Returning total number of INI's that contain i [Re: Joe_Dean]
starbucks_mafia Offline
Hoopy frood

Registered: 09/12/02
Posts: 2962
Loc: Norwich, UK
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.

Top
#201625 - 01/07/08 04:41 PM Re: Returning total number of INI's that contain i [Re: starbucks_mafia]
Joe_Dean Offline
Vogon poet

Registered: 04/05/08
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...


Edited by Joe_Dean (01/07/08 04:42 PM)

Top
#201699 - 02/07/08 05:05 PM Re: Returning total number of INI's that contain i [Re: Joe_Dean]
starbucks_mafia Offline
Hoopy frood

Registered: 09/12/02
Posts: 2962
Loc: Norwich, UK
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.

Top