note 81535 added to function.rmdir

From: Date: Mon, 03 Mar 2008 12:33:39 +0000
Subject: note 81535 added to function.rmdir
Groups: php.notes 
Request: Send a blank email to php-notes+get-136686@lists.php.net to get a copy of this message
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 :) @+ ---- Server IP: 213.246.42.8 Probable Submitter: 130.79.44.224 ---- Manual Page -- http://www.php.net/manual/en/function.rmdir.php Edit -- https://master.php.net/note/edit/81535 Del: integrated -- https://master.php.net/note/delete/81535/integrated Del: useless -- https://master.php.net/note/delete/81535/useless Del: bad code -- https://master.php.net/note/delete/81535/bad+code Del: spam -- https://master.php.net/note/delete/81535/spam Del: non-english -- https://master.php.net/note/delete/81535/non-english Del: in docs -- https://master.php.net/note/delete/81535/in+docs Del: other reasons-- https://master.php.net/note/delete/81535 Reject -- https://master.php.net/note/reject/81535 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#136686) next »