note 94540 deleted from function.rmdir by thiago
| From: | thiago@php.net | Date: | Wed, 11 Nov 2009 11:19:05 +0000 |
| Subject: | note 94540 deleted from function.rmdir by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-162746@lists.php.net to get a copy of this message | ||
Note Submitter: dragos dot rusu at ymail dot com
----
Seems glob function doesn't return the hidden files.
Here's a PHP5 function for deleting a directory tree recursively.
function deleteDirectoryTree($dirPath, $deleteAlsoDirPath = true)
{
$dir_iterator = new RecursiveDirectoryIterator($dirPath);
$iterator = new RecursiveIteratorIterator($dir_iterator,
RecursiveIteratorIterator::CHILD_FIRST);
foreach ($iterator as $file) {
if (is_dir($file) )
{
@rmdir($file);
}
else
{
@unlink($file);
}
}
if ($deleteAlsoDirPath === true && is_dir($dirPath))
{
return @rmdir( $dirPath );
}
}