note 72598 added to function.rmdir
| From: | eli dot hen at gmail dot com | Date: | Thu, 25 Jan 2007 15:54:05 +0000 |
| Subject: | note 72598 added to function.rmdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-122195@lists.php.net to get a copy of this message | ||
This functions deletes or empties the directory.
Without using recursive functions!
<?php
/**
* Removes the directory and all its contents.
*
* @param string the directory name to remove
* @param boolean whether to just empty the given directory, without deleting the given directory.
* @return boolean True/False whether the directory was deleted.
*/
function deleteDirectory($dirname,$only_empty=false) {
if (!is_dir($dirname))
return false;
$dscan = array(realpath($dirname));
$darr = array();
while (!empty($dscan)) {
$dcur = array_pop($dscan);
$darr[] = $dcur;
if ($d=opendir($dcur)) {
while ($f=readdir($d)) {
if ($f=='.' || $f=='..')
continue;
$f=$dcur.'/'.$f;
if (is_dir($f))
$dscan[] = $f;
else
unlink($f);
}
closedir($d);
}
}
$i_until = ($only_empty)? 1 : 0;
for ($i=count($darr)-1; $i>=$i_until; $i--) {
echo "\nDeleting '".$darr[$i]."' ... ";
if (rmdir($darr[$i]))
echo "ok";
else
echo "FAIL";
}
return (($only_empty)? (count(scandir)<=2) : (!is_dir($dirname)));
}
?>
----
Server IP: 192.117.122.43
Probable Submitter: 83.130.255.251
----
Manual Page -- http://www.php.net/manual/en/function.rmdir.php
Edit -- https://master.php.net/note/edit/72598
Del: integrated -- https://master.php.net/note/delete/72598/integrated
Del: useless -- https://master.php.net/note/delete/72598/useless
Del: bad code -- https://master.php.net/note/delete/72598/bad+code
Del: spam -- https://master.php.net/note/delete/72598/spam
Del: non-english -- https://master.php.net/note/delete/72598/non-english
Del: in docs -- https://master.php.net/note/delete/72598/in+docs
Del: other reasons-- https://master.php.net/note/delete/72598
Reject -- https://master.php.net/note/reject/72598
Search -- https://master.php.net/manage/user-notes.php