sh0wtym3 Posted April 7, 2010 Share Posted April 7, 2010 I'm looking for a way to get a list of all subdirectories, and then store them inside an array. There will be a different number of subdirectories each time this script is run. Basically my ftp directory will look something like: rootfolder | subfolder 1 subfolder 2 subfolder 3 My php script will be located inside the "rootfolder". I want to take and store the names of each subfolder into an array, like: $dirArray = ("$subfolder1", "$subfolder2", "$subfolder3"); The problem is I don't know how to search for existing subdirectories and store their names inside an array... Does anyone know how to? Quote Link to comment https://forums.phpfreaks.com/topic/197888-getting-a-list-of-all-subdirectories-and-storing-them-inside-an-array/ Share on other sites More sharing options...
br0ken Posted April 7, 2010 Share Posted April 7, 2010 You will need to write a recursive function (a recursive function is a function that calls itself). The function will be passed a directory, which it will open, iterate through each subdirectory and call itself on that directory. See the following link: http://www.webcheatsheet.com/PHP/working_with_directories.php http://www.php.net/opendir http://www.php.net/readdir Quote Link to comment https://forums.phpfreaks.com/topic/197888-getting-a-list-of-all-subdirectories-and-storing-them-inside-an-array/#findComment-1038550 Share on other sites More sharing options...
Zane Posted April 7, 2010 Share Posted April 7, 2010 you could try using one of these glob statements glob(./*/*.*) glob(~/.*/*) glob(*/*) glob(../*/*) Quote Link to comment https://forums.phpfreaks.com/topic/197888-getting-a-list-of-all-subdirectories-and-storing-them-inside-an-array/#findComment-1038589 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.