The function below returns all folders in a given directory down to multiple levels.
I only need one level depth though, just folders in the target directory, no subfolders.
Also the function returns the full path to the folder, I only want the folder name. I’m sure I’m missing something simple.
How can I modify the function to return only the folder names of the given directory? (not the full paths to each folder)
$myArray = get_dirs(‘../wp-content/themes/mytheme/images’);
<?php
function get_dirs( $path = '.' ){
return glob(
'{' .
$path . '/*,' . # Current Dir
$path . '/*/*,' . # One Level Down
$path . '/*/*/*' . # Two Levels Down, etc.
'}', GLOB_BRACE + GLOB_ONLYDIR );
}
?>
btw, thanks to Doug for the original function help!
Instead of using
glob(), I would suggest using theDirectoryIteratorclass.