Using for Function Define recursive function to delete directories
<html>
<head>
<title>Define recursive function to delete directories </title>
</head>
<body>
<h1>Define recursive function to delete directories </h1>
<?php
function delete_directory ($dir)
{
if ($d = @opendir($dir))
{
while (($file = readdir ($d)) != false)
{
if (($file == ".") || ($file == "..")) continue;
if (is_dir($dir . '/' . $file))
delete_directory($dir . '/' . $file);
else
unlink($dir . '/' . $file);
}
@closedir($d);
rmdir($dir);
}
}
$dir = "./Directory";
delete_directory($dir);
?>
</body>
</html>
Output