Jump to content


Photo

Find files/catalogues Recursive


  • Please log in to reply
2 replies to this topic

#1 mima

mima
  • Members
  • Pip
  • Newbie
  • 2 posts

Posted 16 May 2006 - 08:51 AM

Hello

Lets say I'm in catalogue /home/user1/cat1/

Can I in any way using PHP find every catalogue "after" cat1 i.e
/home/user1/cat1/cat11
/home/user1/cat1/cat12
/home/user1/cat1/cat13
and all files in every catalogue?

I want to be able to create a menu system that the user just by adding a catalogue or file will add an item to current menu.

Thanks!

/MiMa

#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 16 May 2006 - 09:12 AM

This method isn't properly recursive, but it will get what you want I think...
<?php
$handle = opendir("home/user1/cat1/");
while (false !== ($file = readdir($handle))) {
    echo "$file<br/>";
    if(!strpos($file,".")) {
        echo "<ul>";
        foreach(glob("home/user1/cat1/$file/*.*") as $content) {
            echo "<li>$content</li>";
        }
        echo "</ul>";
    }
}
closedir($handle);
?>
Untested, so you might need to tweak it a bit, but is that the kinda thing you wanted to do?

#3 mima

mima
  • Members
  • Pip
  • Newbie
  • 2 posts

Posted 16 May 2006 - 10:56 AM

I think so, I'm not to familiar with PHP syntax (strpos,strpos)
But the logic seems to work for me.

Thanks!

Regards/MiMa

[!--quoteo(post=374230:date=May 16 2006, 04:12 AM:name=SemiApocalyptic)--][div class=\'quotetop\']QUOTE(SemiApocalyptic @ May 16 2006, 04:12 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
This method isn't properly recursive, but it will get what you want I think...
<?php
$handle = opendir("home/user1/cat1/");
while (false !== ($file = readdir($handle))) {
    echo "$file<br/>";
    if(!strpos($file,".")) {
        echo "<ul>";
        foreach(glob("home/user1/cat1/$file/*.*") as $content) {
            echo "<li>$content</li>";
        }
        echo "</ul>";
    }
}
closedir($handle);
?>
Untested, so you might need to tweak it a bit, but is that the kinda thing you wanted to do?
[/quote]





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users