note 115419 deleted from class.directoryiterator by salathe
| From: | salathe@php.net | Date: | Mon, 21 Jul 2014 12:32:49 +0000 |
| Subject: | note 115419 deleted from class.directoryiterator by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-199999@lists.php.net to get a copy of this message | ||
Note Submitter: mike at letsdeliver dot com
----
Remember that this will throw an exception if the directory cannot be opened. You need to catch the
error for proper error handling:
<?php
try {
$iterator = new DirectoryIterator($dir);
}
catch (Exception $e)
{
$error = $e->getMessage();
printf("An error occurred:\n %s\nCouldn't process directory: %s - aborting\n",
$error, $dir);
}
?>
Use this if you're getting a RuntimeException.