Jump to content

Archived

This topic is now archived and is closed to further replies.

mima

Find files/catalogues Recursive

Recommended Posts

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

Share this post


Link to post
Share on other sites
This method isn't properly recursive, but it will get what you want I think... [code]<?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);
?>[/code]
Untested, so you might need to tweak it a bit, but is that the kinda thing you wanted to do?

Share this post


Link to post
Share on other sites
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) [snapback]374230[/snapback][/div][div class=\'quotemain\'][!--quotec--]
This method isn't properly recursive, but it will get what you want I think... [code]<?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);
?>[/code]
Untested, so you might need to tweak it a bit, but is that the kinda thing you wanted to do?
[/quote]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.