Don't store DirectoryIterator objects for later; you will get an error saying "too many open files" when you store more than the operating system limit (usually 256 or 1024).
For example, this will yield an error if the directory has too many files:
<?php
$files = array();
foreach (new DirectoryIterator('myDir') as $file) {
$files[] = $file;
}
?>
Presumably, this approach is memory intensive as well.