0

I am using this code to list the name of ll existing Folders in a Directory but it is returning all folders, images, files (everything) in the directory.

<?php // open this directory $myDirectory = opendir($_SERVER['DOCUMENT_ROOT'] . "/."); $list = 0; while (false !== ($entryName = readdir($myDirectory))) { if ($entryName != "." && $entryName != ".." && $entryName != ".DS_Store") { $dirArray[] = $entryName; } } 

How can I modify it to get ONLY Folders Name in the directory?

2
  • thanks str, I tried this already like this way 'if (is_dir($entryName)) { $dirArray[] = $entryName;} but I got empty dots instead of the file names and the inks also didn't work Commented Apr 29, 2014 at 19:25
  • Not sure what you mean. What are "empty dots"? Why should there be file names if you only want directories? And your code does not include any type of "links". Commented Apr 29, 2014 at 19:30

1 Answer 1

2

I think this will work:

<?php $foldersandfiles = scandir($_SERVER['DOCUMENT_ROOT'] . "/."); foreach( $foldersandfiles as $folderorfile ) { if( $folderorfile != '.' && $folderorfile != '..' && is_dir($_SERVER['DOCUMENT_ROOT'] . '/' . $folderorfile) ) { $dirArray[] = $folderorfile; } } 

Please give it a go.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Joans, This is what I was looking for it

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.