note 50438 deleted from function.rmdir by aidan
| From: | aidan@php.net | Date: | Wed, 15 Apr 2009 04:29:23 +0000 |
| Subject: | note 50438 deleted from function.rmdir by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153279@lists.php.net to get a copy of this message | ||
Note Submitter: itsdapead
----
Warning! On Unix-type systems, most of the "delete directory tree" functions posted here
will follow & delete symbolic links (which is not what you'd expect of, say, rm-rf) so you
might find more than you bargained for getting wiped.
Here's a quick kludge of an earlier submission (by tekangel) that avoids this by default.
Make sure it does what you want before you uncomment the unlink and rmdir commands!
<?
function rmdirRecursive($path,$followLinks=false) {
$dir = opendir($path) ;
while ( $entry = readdir($dir) ) {
if ( is_file( "$path/$entry" ) || ((!$followLinks) &&
is_link("$path/$entry")) ) {
echo ( "unlink $path/$entry;\n" );
// Uncomment when happy!
//unlink( "$path/$entry" );
} elseif ( is_dir( "$path/$entry" ) && $entry!='.' &&
$entry!='..' ) {
rmdirRecursive( "$path/$entry" ) ;
}
}
closedir($dir) ;
echo "rmdir $path;\n";
// Uncomment when happy!
// return rmdir($path);
}
?>