Page 1 of 1

Array Based Directory Tree

Posted: Tue Apr 18, 2006 6:29 am
by printf
I've been trying to figure a way to make a directory structured array, where directories are array(s) and files are string(s), keeping the exact format of the directory and all the directories and files it has, no matter how deep it goes! I have looked at hundreds of so called array based tree(s) but none of them, maintain a true array based directory structure.

I know I can do this with eval();, when looping, splitting the directory separator '/' and building the array that way, but I am wondering if there is some way to do it without using eval();


tia

pif!

Posted: Tue Apr 18, 2006 8:14 am
by feyd
PHP4 or PHP5?

Posted: Tue Apr 18, 2006 9:21 am
by Chris Corbyn
You need to create a recursive function (yay!! :)) that opens a directory, loops over all files (except "." and ".." or it will never end), checks if it is a directory with is_dir() and recurses into it if it is, else it adds a string to the currect level of the array.

I can post it if you get stuck cos they can be a bit confusing if you're not used to recursion but you'll be good to try it yourself :)

Posted: Tue Apr 18, 2006 12:12 pm
by printf
php 5 is fine...

There is this javascript tree menu...

http://www.softcomplex.com/products/tigra_tree_menu/

That expects that the format of the built JavaScript array be exactly how a directory is structured. I'll post what I am using now in a few minutes, I know there must be more simpler way (no eval()), but I can't seem to wrap my head around it.


pif!

Posted: Tue Apr 18, 2006 3:03 pm
by feyd
two possible solutions I posted here: viewtopic.php?t=47288