[SOLVED] Recurse folders & files
Posted: Sun Oct 31, 2004 12:18 pm
New here. Looks like a great place to get some answers. I won't be long winded.
I have a folder structure that has images in the respective folders. I have a script that recurses these folders fine and prints out a directory tree. My question is: How can I just pull out the thumbnail images (prefixed "thumb_") and print out the same tree with only the thumbnail image links.
The ultimate goal is to populate a xml file with the paths as an element. Actually to go further, how would I get it to just give me the path filenames and no folder output.
OK, one question at a time. Don't want to get too greedy. The latter is not that important right now. Thanks.
I have a folder structure that has images in the respective folders. I have a script that recurses these folders fine and prints out a directory tree. My question is: How can I just pull out the thumbnail images (prefixed "thumb_") and print out the same tree with only the thumbnail image links.
Code: Select all
<?php
create_tree(".");
function create_tree($file_dir)
{
if ($handle = @opendir($file_dir))
{
$i=0;
while (false !== ($file = @readdir($handle))) {
if ($file != "." && $file != "..") {
$list[$i]=$file;
$i++;
}
}
$dir_length = count($list);
echo "<ul>";
for($i=0;$i<$dir_length;$i++)
{
if(strrpos($list[$i], ".") == FALSE)
{
echo "<li>".$list[$i]."/</li>\n";
create_tree($file_dir."/".$list[$i]);
}
else
{
echo "<li><a href="".$file_dir."/".$list[$i]."">".$list[$i]."</a></li>\n";
}
}
echo "</ul>";
closedir($handle);
}
}
?>OK, one question at a time. Don't want to get too greedy. The latter is not that important right now. Thanks.