|
||||||
| PHP Forum Use this forum to discuss all aspects of PHP Development. PHP is a server-side, cross-platform, HTML embedded scripting language that lets you create dynamic web pages. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
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?
__________________
DirkFirst |
| Sponsored Links |
|
|
|
|||
|
Code:
$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);
Most of this code came from: http://www.laughing-buddha.net/jon/php/dirlist/ |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
| WingedPanther | ........ | 2753.6 |
| Xav | ........ | 2704 |
| Brandon W | ........ | 1702.32 |
| John | ........ | 1207.73 |
| marwex89 | ........ | 1175.24 |
| morefood2001 | ........ | 966.05 |
| dcs | ........ | 655.75 |
| Steve.L | ........ | 475.59 |
| orjan | ........ | 418.58 |
| Aereshaa | ........ | 383.54 |
Goal: 100,000 Posts
Complete: 98%