How can I find the number of iles and directories and folder? I only want to count certain file type extensions such as .html, .htm, .php etc. Anyone can help me with the code to do this?
Number of files and directories in folder
Started by dirkfirst, May 20 2006 04:39 AM
4 replies to this topic
#1
Posted 20 May 2006 - 04:39 AM
|
|
|
#2
Posted 25 May 2006 - 03:36 PM
Anyone?
#3
Posted 28 May 2006 - 09:14 AM
$directory = "/"
// create an array to hold directory list
$results = array();
// create a handler for the directory
$handler = opendir($directory);
// Create a total file counter
$totalFiles = 0;
// Create counter for file types
$myFiles = 0;
// keep going until all files in directory have been read
while ($file = readdir($handler)) {
// if $file isn't this directory or its parent,
// add it to the results array
if ($file != '.' && $file != '..') {
// Counter for total files
$totalFiles++;
// Get our extension
$myExt = substr($file,strlen($file)-3);
// Test our string
if ($myExt == ".doc" || $myExt == ".txt") { // Replace .doc and .txt here
$myFiles++;
}
}
}
// close the handler
closedir($handler);
I didn't include directories but you can work that out from the code above.
Most of this code came from: http://www.laughing-...on/php/dirlist/
#4
Posted 28 May 2006 - 04:17 PM
Great! Thank you. I'll work out the rest from that. I've actually learned a lot about PHP since I posted this.
#5
Posted 30 May 2006 - 07:06 AM
Nice scripts, i'm going to save that one for later use.
Thanks.
Thanks.


Sign In
Create Account


Back to top









