#native_company# #native_desc#
#native_cta#

dir and subdir search and size

By Chris from wappyCULT
on June 29, 2006

Version: 1.00wappy

Type: Function

Category: File Management

License: Other

Description: A great bit of code i was given ages ago. I have added filesize though. To see a working example (if you got opera or some other WAP browser) see http://cult.toddywap.com

I used this with an input box on my site like...
search($target, $directory)...... It will search the directory and sub directorys. 
<?
function search($target, $directory){

   if(is_dir($directory)){
       $direc = opendir($directory);
       while(false !== ($file = readdir($direc))){

           if($file !="." && $file != ".."){

               if(is_file($directory."/".$file)){
                   if(preg_match("/$target/i", $file)){

$size = round(filesize($directory."/".$file)/1024,1);                                           echo "<a href="$directory/$file">$file ($size KB)</a><br>";
                                       }
               }else if(is_dir($directory."/".$file)){
                   search($target,$directory."/".$file);

               }

           }
       }
       closedir($direc);
   }

   return ;
}
?>