Jump to content

Getting a list of all subdirectories and storing them inside an array


Recommended Posts

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?

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

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.