note 77476 deleted from function.rmdir by aidan
| From: | aidan@php.net | Date: | Wed, 15 Apr 2009 04:23:32 +0000 |
| Subject: | note 77476 deleted from function.rmdir by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153250@lists.php.net to get a copy of this message | ||
Note Submitter: bluej100@gmail
----
Here's my stack-based pseudo-recursive rmdir. It borrows heavily from andy at mentalist's.
<?php
function rmdir_r($path) {
if (!is_dir($path)) {return false;}
$stack = Array($path);
while ($dir = array_pop($stack)) {
if (@rmdir($dir)) {continue;}
$stack[] = $dir;
$dh = opendir($dir);
while (($child = readdir($dh)) !== false) {
if ($child[0] == '.') {continue;}
$child = $dir . DIRECTORY_SEPARATOR . $child;
if (is_dir($child)) {$stack[] = $child;}
else {unlink($child);}
}
}
return true;
}
?>