What are some best practices for displaying additional information like modification date or file size when using RecursiveIteratorIterator in PHP?

When using RecursiveIteratorIterator in PHP to iterate over files and directories, you may want to display additional information like modification date or file size. One way to achieve this is by accessing the file information using the SplFileInfo class within the loop. This allows you to easily retrieve and display the desired information for each file or directory.

$directory = new RecursiveDirectoryIterator('path/to/directory');
$iterator = new RecursiveIteratorIterator($directory);

foreach ($iterator as $file) {
    $info = new SplFileInfo($file);
    echo 'File: ' . $info->getFilename() . ' | Size: ' . $info->getSize() . ' | Modified: ' . date('Y-m-d H:i:s', $info->getMTime()) . PHP_EOL;
}