View Single Post
  #3 (permalink)  
Old 05-28-2006, 01:14 PM
RobSoftware RobSoftware is offline
Programmer
 
Join Date: Nov 2005
Posts: 143
Credits: 0
Rep Power: 12
RobSoftware is on a distinguished road
Default

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);
I didn't include directories but you can work that out from the code above.
Most of this code came from: http://www.laughing-buddha.net/jon/php/dirlist/
Reply With Quote