note 55075 deleted from function.rmdir by aidan
| From: | aidan@php.net | Date: | Wed, 15 Apr 2009 04:28:43 +0000 |
| Subject: | note 55075 deleted from function.rmdir by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153273@lists.php.net to get a copy of this message | ||
Note Submitter: makarenkoa at ukrpost dot net
----
<?php
// rmdirr.inc.php
/*
25.07.2005
Author: Anton Makarenko
makarenkoa at ukrpost dot net
webmaster at eufimb dot edu dot ua
Original idea:
http://ua2.php.net/manual/en/function.rmdir.php
28-Apr-2005 07:35
development at lab-9 dot com
*/
function rmdirr($target,$verbose=false)
// removes a directory and everything within it
{
$exceptions=array('.','..');
if (!$sourcedir=@opendir($target))
{
if ($verbose)
echo '<strong>Couldn’t open '.$target."</strong><br
/>\n";
return false;
}
while(false!==($sibling=readdir($sourcedir)))
{
if(!in_array($sibling,$exceptions))
{
$object=str_replace('//','/',$target.'/'.$sibling);
if($verbose)
echo 'Processing: <strong>'.$object."</strong><br />\n";
if(is_dir($object))
rmdirr($object);
if(is_file($object))
{
$result=@unlink($object);
if ($verbose&&$result)
echo "File has been removed<br />\n";
if ($verbose&&(!$result))
echo "<strong>Couldn’t remove file</strong>";
}
}
}
closedir($sourcedir);
if($result=@rmdir($target))
{
if ($verbose)
echo "Target directory has been removed<br />\n";
return true;
}
if ($verbose)
echo "<strong>Couldn’t remove target directory</strong>";
return false;
}
/*
// sample usage
<?php
require('./lib/rmdirr.inc.php');
rmdirr('D:/srv/Apache2/htdocs/testRm',true);
?>
//*/
?>