note 7547 deleted from function.rmdir by jimw
| From: | jimw@php.net | Date: | Wed, 02 Jan 2002 01:27:16 +0000 |
| Subject: | note 7547 deleted from function.rmdir by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-24086@lists.php.net to get a copy of this message | ||
To delete A direcotry recursively you can use the following function:
<?
$directory =
"/full/or/relative/path/to/the/directory/that/you/want/to/recursively/delete/";
if (!file_exists($directory)) {
print "Directory not found!";
die;
}
function deldir($location) {
if (substr($location,-1) <> "/")
$location = $location."/";
$all=opendir($location);
while ($file=readdir($all)) {
if (is_dir($location.$file) && $file <> ".." && $file <>
".") {
deldir($location.$file);
rmdir($location.$file);
print "Removed directory ($location$file)\n";
unset($file);
} elseif (!is_dir($location.$file)) {
unlink($location.$file);
print "Removed file ($location$file)\n";
unset($file);
}
}
rmdir($location);
}
?>
<html>
<head>
<title>
RCDWPHP - Stallion
</title>
</head>
<body>
<pre>
<b>Recursive Directory Deletion With PHP - <a href='mailto:clambert@gamespy.com'>Stallion</a></b>
<? deldir($directory); ?>
</pre>
</body>
</html>";