General Community > Scripting Help

script to count files with an extension

<< < (2/2)

Metho:
Use that instead of my ereg_replace, please. Thanks, [Unknown]. :D

Methonis

chris:
Take a look at: http://de.php.net/manual/en/function.pathinfo.php and http://de.php.net/manual/en/function.basename.php

untested:


--- Code: ---<?php 

   $files = array();
   $dir = @opendir(&#39;/usr/home/web/users/a0013745/html/RodSerling/Chat/poets&#39;);
   while (($file = readdir($dir)) !== false)
   {
      $parts   = pathinfo($file);
      if ($path_parts[&#39;extension&#39;] == &#39;.who&#39;)
      {
         $files[] = basename($parts[&#39;basename&#39;],&#39;.who&#39;);
      }
   } 
   closedir($dir);
   sort($files);

   // Output results
   echo count($files).&#39; files match<br />&#39;;
   foreach($files AS $name)
   {
      echo $name;
   }

?>
--- End code ---

;D

Navigation

[0] Message Index

[*] Previous page

Go to full version