rfresh
03-01-2009, 08:14 PM
Is there a PHP script that can count the total number of files on my website? I need to find out how many files are on my site.
Thanks...
Thanks...
|
||||
How to count all files on my website?rfresh 03-01-2009, 08:14 PM Is there a PHP script that can count the total number of files on my website? I need to find out how many files are on my site. Thanks... xconspirisist 03-01-2009, 10:01 PM If you are using php5, you could try something like this; <?php $count = sizeof(scandir('./')); echo 'There are ' . $count . ' files in this directory on my website.'; ?> Fou-Lu 03-01-2009, 11:50 PM That will work for any single directory. Are you asking how to do it over multiple sub-directories as well? Oh yeah, and do you count a directory as a file or exclude the count? rfresh 03-02-2009, 12:59 AM Yes, across multiple sub-directories... Fou-Lu 03-02-2009, 03:12 AM You didn't mention if you're using PHP5 or not, but thats ok. Try this: $dir = getcwd(); printf("Files in directory %s: %d\n", realpath($dir), countDirectoryFiles($dir)); function countDirectoryFiles($scanDir = null) { $iFileCount = 0; if (is_file($scanDir)) { ++$iFileCount; } else if (is_dir($scanDir)) { if (false !== ($dh = opendir($scanDir))) { while (false !== ($file = readdir($dh))) { if ($file != '.' && $file != '..') { $iFileCount += countDirectoryFiles($scanDir . DIRECTORY_SEPARATOR . $file); } } closedir($dh); } } return $iFileCount; } rfresh 03-02-2009, 05:14 AM Tha worked perfectly...thanks... sashkat 03-28-2009, 11:35 AM Is it possible to modify this script so that it counts the folders in a particular directory, the counts jpg files in only one sub folder in the same directory? I'm still new to php :) Thank you |
| |||
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum