note 51395 modified in function.opendir by danbrown
| From: | danbrown@php.net | Date: | Fri, 24 Jul 2009 15:51:17 +0000 |
| Subject: | note 51395 modified in function.opendir by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-158697@lists.php.net to get a copy of this message | ||
Here is a snippet of the code that I created to search for a file..recursively open the directories
and search for a match..
<?php
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)){
echo "<a href=\"$directory/$file\">$file</a><br>";
}
}else if(is_dir($directory."/".$file)){
search($target,$directory."/".$file);
}
}
}
closedir($direc);
}
return ;
}
?>
--was--
Here is a snippet of the code that I created to search for a file..recursively open the directories
and search for a match..
<?
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)){
echo "<a href=\"$directory/$file\">$file</a><br>";
}
}else if(is_dir($directory."/".$file)){
search($target,$directory."/".$file);
}
}
}
closedir($direc);
}
return ;
}
?>
http://php.net/manual/en/function.opendir.php