Voting

: nine minus one?
(Example: nine)

The Note You're Voting On

chrys at mytechjournal dot com
19 years ago
I wrote a function to recursively delete files from a starting directory. I had to do this because my server doesn't allow me to delete files that apache writes because I don't have permissions, so... I let apache do the work.

<?php
$dir
= "/path/to/base/dir";

recursive_delete($dir);

function
recursive_delete( $dir )
{
if (
is_dir($dir)) {
if (
$dh = opendir($dir)) {
while ((
$file = readdir($dh)) !== false ) {
if(
$file != "." && $file != ".." )
{
if(
is_dir( $dir . $file ) )
{
echo
"Entering Directory: $dir$file<br/>";
recursive_delete( $dir . $file . "/" );
echo
"Removing Directory: $dir$file<br/><br/>";
rmdir( $dir . $file );
}
else
{
echo
"Deleting file: $dir$file<br/>";
unlink( $dir . $file );
}
}
}
closedir($dh);
}
}
}
?>

<< Back to user notes page

To Top