note 81997 deleted from function.rmdir by danbrown

From: Date: Tue, 10 Mar 2009 19:42:36 +0000
Subject: note 81997 deleted from function.rmdir by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-151704@lists.php.net to get a copy of this message
Note Submitter: rjcarr at gmail dot com ---- To the poster on 03-Mar-2008 05:33, if the directory contains more than one file, your rmdir($f) will (silently) warn that the dir isn't empty. I think the following, although not quite as elegant, fixes the problem. <?php function deltree($f) { if (is_dir($f)) { foreach(glob($f.'/*') as $sf) { if (is_dir($sf) && !is_link($sf)) { deltree($sf); rmdir($sf); } else { unlink($sf); } } } rmdir($f); } ?>

« previous php.notes (#151704) next »