$dir = new RecursiveDirectoryIterator('path/to/directory'); $iterator = new RecursiveIteratorIterator($dir); foreach ($iterator as $file) { if ($iterator->isDir()) { echo 'Directory: ' . $file->getPathname() . PHP_EOL; } else { echo 'File: ' . $file->getPathname() . PHP_EOL; } }In this example, we create a new instance of RecursiveDirectoryIterator for the directory we want to iterate over, and then pass that to a new instance of RecursiveIteratorIterator. We then use a foreach loop to iterate over the iterator and check if each item is a directory or not using the isDir method. This code example can be found in the PHP documentation for RecursiveIteratorIterator, which is part of the SPL (Standard PHP Library) package library.