note 81535 deleted from function.rmdir by aidan

From: Date: Wed, 15 Apr 2009 04:21:57 +0000
Subject: note 81535 deleted from function.rmdir by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-153237@lists.php.net to get a copy of this message
Note Submitter: boccheciampe at dpt-info.u-strasbg.fr ---- About the improved deltree function from lukas at example dot com (and first one from vboedefeld at googlemail dot com) : I'm not sure but it looks like the function doesn't delete the very first directory : # mkdir -p /tmp/foo/{test1,test2} # php deltree.php /tmp/foo # ls -l /tmp/foo/ total 0 My directory "foo" is still there. Unless it is what you really want the function to do, I think the "rmdir($sf)" is at the wrong place. The new improved function is : <?php function deltree($f) { if (is_dir($f)) { foreach(glob($f.'/*') as $sf) { if (is_dir($sf) && !is_link($sf)) { deltree($sf); // rmdir($sf); <== old place with arg "$sf" } else { unlink($sf); } rmdir($f); // <== new place with new arg "$f" } } else { die("Error: not a directory - $f"); } } ?> Let me know if I'm wrong :) @+

« previous php.notes (#153237) next »