News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Count files in a directory where name = and output number to a variable.

Started by MoreBloodWine, June 13, 2015, 12:12:13 AM

Previous topic - Next topic

MoreBloodWine

Ok this ones a bit on the trickier side... so I would love it if someone could figure this one out for me.

Anyway, using php, how can one count the number of files in a directory where name = preg_match("/(.*)_lottery.inc.php/") and then output that total to a variable, which right now would equal 3 as a result... Ty.
Want a sig like mine for your BTCGuild stats ? Then check this out: Spend-ur-Bits


margarett

You need to run through the files in the given folder and compare each file's name. I'll throw something for you tomorrow ;)
(nudge me if I forget :P )
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

MoreBloodWine

Quote from: margarett on June 13, 2015, 04:46:52 PM
You need to run through the files in the given folder and compare each file's name. I'll throw something for you tomorrow ;)
(nudge me if I forget :P )
Deleted my last reply, didn't realized you replied to this lol...

Anyway, here's the original button code to help simplify things.

I have $number_of_lotteries defined at the top of the file as 3 but ya, basically I'd like to count the files in a specified folder where: $number_of_lotteries = preg_match("/(.*)_lottery/", $page) <-- name of the files.

              <li <?php if ($page == 'lotteries' || preg_match("/(.*)_lottery/"$page)) { echo 'class="active"'; } ?>>
                <a href="index.php?page=lotteries">Lotteries (<?php echo $number_of_lotteries?>)</a>
              </li>
Want a sig like mine for your BTCGuild stats ? Then check this out: Spend-ur-Bits


MoreBloodWine

I think your the one who took BTC from me before as payment, while it might not be much I can send you 0.01 BTC when a deposit clear my wallet if you wanted to pluck at this sometime today ;-)
Want a sig like mine for your BTCGuild stats ? Then check this out: Spend-ur-Bits


margarett

I wasn't, no. I haven't had any BTC experience yet

Today is not an option, I am out of the country with no computer near me. Only when I get home tomorrow ;)
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

MoreBloodWine

Quote from: margarett on June 13, 2015, 05:00:51 PM
I wasn't, no. I haven't had any BTC experience yet

Today is not an option, I am out of the country with no computer near me. Only when I get home tomorrow ;)
Thats cool, figured I'd toss the BTC thing out there because someone from here took it as payment once heh
Want a sig like mine for your BTCGuild stats ? Then check this out: Spend-ur-Bits


MoreBloodWine

This whole thing with the edit link going by by after so much time is irking me, so here goes another reply which is a no no because posts shouldnt be bumped which I'm not trying to do.

Apparently preg_match returns an array and my whole brain fried state is messing with me.

Basically This is to do with making something on my crypto site a bit easier as in the long one it will be one less thing for me to manually manage, anyway...

I need to count files in folder (path/to/me) who's names match *_lottery.inc.php where the * is a wild card since files might be named such as...

hello_lottery.inc.php
and_lottery.inc.php
goodbye_lottery.inc.php

So the output would be 3


Problem solved, less you think this can be done cleaner...

<?php

$directory '/path/to/files/';
$files glob($directory "*_lottery.inc.php");

if ( $files !== false )
{
$number_of_lotteries count$files );
echo "<li ";
  if ($page == 'lotteries' || preg_match("/(.*)_lottery/"$page)) { echo 'class="active"'; } 
echo '>
                <a href="index.php?page=lotteries">Lotteries ('
;
echo $number_of_lotteries;
echo ")</a>
              </li>
  "
;
}

?>

Want a sig like mine for your BTCGuild stats ? Then check this out: Spend-ur-Bits


Advertisement: