You are here: Re: Command « All PHP « IT news, forums, messages
Re: Command

Posted by thib΄ on 01/13/08 19:29

Fred Atkinson wrote:
> I've looked at php.net and am not able to find this one.
>
> What is the function that will return the number of files in a
> subdirectory?
>
> Regards,
>
>
>
> Fred

Just try this one:
<?php
function countfiles($dir) {
if( $handle = opendir($dir) ) {
$c = 0;
while( $file = readdir($handle) )
if( !preg_match('/\.\.?/', $file) ) $c++;
return $c;
} else return false;
}
?>

This should make it; you can of course change de regexp filter or use
different methods (this one only avoids counting '.' and '..')

Call example:

Number of files in subdir 'dir/subdir/' is <?php echo
countfiles('dir/subdir/') or '[warning: unable to open dir]'; ?>

-thibΒ΄

 

Navigation:

[Reply to this message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация