Is there a PHP function that will tell me the number of files in a directory that have a certain extension? Or, even better, a function that will take all the files with a given extension that are in a given directory and put their filenames in an array. Thanks!
You can find your problem solved in here: http://www.php.net/manual/en/function.opendir.php
I have a tendency to miss things, however, I don't see anywhere on that page where it mentions my problem. Is there a way to look at more posts by users than there are listed on this first page? If not, I'm still lost....
<?php if ($dir = @opendir("/tmp")) { count = 0; while (($file = readdir($dir)) !== FALSE) { $count++; } closedir($dir); print($count . ' files'); } ?>
Thanks, I'll try that! But what about putting it into an array? Is that possible?
<?php if ($dir = @opendir("/tmp")) { while (($file = readdir($dir)) !== FALSE) { $arrayoffiles[count($arrayoffiles)] = $file; //$arrayoffiles[count($arrayoffiles)] = $dir . $file; } closedir($dir); } ?>
Originally posted by Trid3nt Is there a PHP function that will tell me the number of files in a directory that have a certain extension? Or, even better, a function that will take all the files with a given extension that are in a given directory and put their filenames in an array. Thanks!
<? function GetFilesList ($dir) { $handle=opendir($dir); while ($file = readdir($handle)) if(!is_dir($file) && $file!="." && $file!="..") $Fileslist[$file]=$file; closedir($handle); return $Fileslist; } echo "total:".count(GetFilesList (".")); ?>
it return nb file of file if u want more i suggest that u see search.php in philex package 😉
http://sourceforge.net/project/showfiles.php?group_id=46975
Thank you very much! I'm going to test this out sometime this week and get it rolling. The help is MUCH appreciated!