How can I Get all subdirectories of a given directory (without files and "." or "..") and then use each directory in a function?
Thanks.
How can I Get all subdirectories of a given directory (without files and "." or "..") and then use each directory in a function?
Thanks.
you can use glob() with GLOB_ONLYDIR
option
or
$dirs = array_filter(glob('*'), 'is_dir');
print_r( $dirs);
Almost the same as in your previous question:
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($yourStartingPath),
RecursiveIteratorIterator::SELF_FIRST);
foreach($iterator as $file) {
if($file->isDir()) {
echo strtoupper($file->getRealpath()), PHP_EOL;
}
}
Replace strtoupper
with your desired function.
Sry for answering an old post, but here's how you can retrieve only directories with GLOB:
$directories = glob($somePath . '/*' , GLOB_ONLYDIR);