Skip to content

Instantly share code, notes, and snippets.

@stavrossk
Last active December 20, 2015 22:08
Show Gist options
  • Save stavrossk/6202336 to your computer and use it in GitHub Desktop.
Save stavrossk/6202336 to your computer and use it in GitHub Desktop.
PHP: An array of sub-directories of a directory.
<?php
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>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment