Well since no one helped me with my last post a while back (2 or 3 weeks ago)...I have little hope for help this time...but after spending time trying to figure this out, I have come to get help from you all.
<?php
// Directory to iterate over
$root_directory = "/home/user1/public_html/directory";
/* Folder to originate from, if left blank then will recurse through entire tree: */
$path_extension = "";
// The file name to look for
$check_file = "unitinfo.txt";
function recursive_dir($root, $path_ext = "", $check_ext = "", $new_path_ext = "") {
$dh = opendir($root.$path_ext.$new_path_ext);
while(false !== ($entry=readdir($dh))) {
if($entry != "." && $entry != ".." && is_dir($root.$path_ext.$new_path_ext."/".$entry)) {
$prev_path_ext = $new_path_ext;
$new_path_ext .= "/".$entry;
recursive_dir($root,$path_ext,$check_ext,$new_path_ext);
//echo "Closing Path: ".$root.$path_ext.$new_path_ext."<br>\n";
$new_path_ext = $prev_path_ext;
}
elseif($entry != "." && $entry != ".." && eregi("($check_ext)$",$entry)) {
$items[] = $root."/".$new_path_ext."/".$entry;
/ * This works for echoing the array in the function
foreach ($items as $key){
echo $key;
}
*/
return $items;
}
}
closedir($dh);
}
$newList = recursive_dir($root_directory, $path_extension, $check_file);
for($i=0; $i < count($newList); $i++)
echo "$newList[$i]<br>";
?>
Some of this code was found online...some of it rewritten by me. I am just trying to have the code go into directories and find this file called unitinfo.txt, and bring back the full path to it including the file name...e.g. /some/dir/unitinfo.txt
I can echo the array from in the function no problem, but I need to return the array so I can throw it into another function/or another loop rather so I can manip the data/use it.
The above code does not work 🙁
Any help appreciated