how to get the subdirectory paths into an array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
purpleglow
Forum Newbie
Posts: 1
Joined: Sun Oct 18, 2009 8:14 am

how to get the subdirectory paths into an array

Post by purpleglow »

i have a directory called 'images' and there are subdirectories like 'images/dir1/end/' , 'images/dir2/' and 'images/dir5/dir65/dr/'

Now i'd like to get the pathnames into an array only for these deepest subdirectories that are under the images directory.
So I only want pathnames for these 'images/dir1/end/' , 'images/dir2/' and 'images/dir5/dir65/dr/', not the ones like 'images' or 'images/dir5' or 'images/dir5/dir65'.

Any easy solutions for this?

Thanks a lot.
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: how to get the subdirectory paths into an array

Post by Eric! »

If you know how to find the path names or strings you can use these functions to extract paths:
http://www.php.net/manual/en/function.dirname.php
http://www.php.net/manual/en/function.pathinfo.php

If you're looking for a way to find the paths because you don't know them all try glob()
http://php.net/manual/en/function.glob.php

There are some examples showing how to search out the directory trees.
Post Reply