note 76806 deleted from function.rmdir by aidan

From: Date: Wed, 15 Apr 2009 04:23:38 +0000
Subject: note 76806 deleted from function.rmdir by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-153251@lists.php.net to get a copy of this message
Note Submitter: swizec at swizec dot com ---- Here is a better recursive rmdir function, that relies on php's built-in dir class and doesn't use messy directory changing. <?php function full_rmdir( $dir ) { if ( !is_writable( $dir ) ) { if ( !@chmod( $dir, 0777 ) ) { return FALSE; } } $d = dir( $dir ); while ( FALSE !== ( $entry = $d->read() ) ) { if ( $entry == '.' || $entry == '..' ) { continue; } $entry = $dir . '/' . $entry; if ( is_dir( $entry ) ) { if ( !$this->full_rmdir( $entry ) ) { return FALSE; } continue; } if ( !@unlink( $entry ) ) { $d->close(); return FALSE; } } $d->close(); rmdir( $dir ); return TRUE; } ?>

« previous php.notes (#153251) next »