eddy556 Posted June 18, 2007 Share Posted June 18, 2007 Are there any functions available in php that will count the amount of files in a folder + its subfolders and return the answer? I'm sure there must be a simple answer for this Thanks Link to comment https://forums.phpfreaks.com/topic/56048-return-the-amount-of-files-in-a-folder-including-subfolders/ Share on other sites More sharing options...
per1os Posted June 18, 2007 Share Posted June 18, 2007 www.php.net/dir (Qube#php@Efnet) 15-May-2007 08:36 <?php // Sample function to recursively return all files within a directory. // http://www.pgregg.com/projects/php/code/recursive_readdir.phps Function listdir($start_dir='.') { $files = array(); if (is_dir($start_dir)) { $fh = opendir($start_dir); while (($file = readdir($fh)) !== false) { # loop through the files, skipping . and .., and recursing if necessary if (strcmp($file, '.')==0 || strcmp($file, '..')==0) continue; $filepath = $start_dir . '/' . $file; if ( is_dir($filepath) ) $files = array_merge($files, listdir($filepath)); else array_push($files, $filepath); } closedir($fh); } else { # false if the function was called with an invalid non-directory argument $files = false; } return $files; } $files = listdir('.'); print_r($files); ?> Probably just have to count the array instead of printing it to get the file numbers. Link to comment https://forums.phpfreaks.com/topic/56048-return-the-amount-of-files-in-a-folder-including-subfolders/#findComment-276831 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.