note 75473 deleted from function.rmdir by aidan
| From: | aidan@php.net | Date: | Wed, 15 Apr 2009 04:24:39 +0000 |
| Subject: | note 75473 deleted from function.rmdir by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153255@lists.php.net to get a copy of this message | ||
Note Submitter: brousky - gmail
----
equivalent of :
rmdir -rf
ie. remove a directory and everything that's in it. Note that after calling this function the
current working directory of the script will be the parent of the directory you deleted.
<?php
function rmdir_rf($dirname) {
if ($dirHandle = opendir($dirname)) {
chdir($dirname);
while ($file = readdir($dirHandle)) {
if ($file == '.' || $file == '..') continue;
if (is_dir($file)) rmdir_rf($file);
else unlink($file);
}
chdir('..');
rmdir($dirname);
closedir($dirHandle);
}
}
?>