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!
Array Based Directory Tree
Moderator: General Moderators
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
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
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
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!
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!
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
two possible solutions I posted here: viewtopic.php?t=47288