note 92661 modified in function.rmdir by danbrown
| From: | danbrown@php.net | Date: | Sat, 29 Aug 2009 02:24:31 +0000 |
| Subject: | note 92661 modified in function.rmdir by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-160018@lists.php.net to get a copy of this message | ||
I wasn't having much luck with the recursive delete functions below, so I wrote my own:
<?php
// ensure $dir ends with a slash
function delTree($dir) {
$files = glob( $dir . '*', GLOB_MARK );
foreach( $files as $file ){
if( substr( $file, -1 ) == '/' )
delTree( $file );
else
unlink( $file );
}
rmdir( $dir );
}
?>
Simple. Works.
--was--
I wasn't having much luck with the recursive delete functions below, so I wrote my own:
<?
// ensure $dir ends with a slash
function delTree($dir) {
$files = glob( $dir . '*', GLOB_MARK );
foreach( $files as $file ){
if( substr( $file, -1 ) == '/' )
delTree( $file );
else
unlink( $file );
}
rmdir( $dir );
}
?>
Simple. Works.
http://php.net/manual/en/function.rmdir.php