The following function lists all subdirectories in a directory:
- function listdir($dir){
- if ($handle = opendir($dir)){
- $output = array() ;
- while (false !== ($item = readdir($handle))){
- if (is_dir($dir.'/'.$item) and $item != "." and $item != ". ."){
- $output[] = $dir.'/'.$item;
- $output = array_merge($output, ListDescendantDirectories($dir.'/'.$item));
- }
- }
- closedir( $handle);
- return $output;
- }else{
- return false;
- }
- }
- $dirs = listdir('myDirectory');
- foreach($dirs as $dir){
- echo $dir.'< ;br>';
- }
- ?>
Copy code
|