Jump to content

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


sh0wtym3

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

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.