note 103140 added to function.rmdir

From: Date: Mon, 28 Mar 2011 20:44:46 +0000
Subject: note 103140 added to function.rmdir
Groups: php.notes 
Request: Send a blank email to php-notes+get-178277@lists.php.net to get a copy of this message
i extended the last proposal by two (for my understanding) important features: - atomicity if the operation fails somewhere in the recursive tree, we have a half-deleted folder. this is not nice. i added a recursive check wether the folder (and everything in it) is writeabel. the deletion is not started if the check fails. - return value - according to this check. true if the folder was be deleted, false otherwise. function checkRightsRec($dir) { $right = is_writable($dir); if ($right && is_dir($dir)) { $objects = scandir($dir); $curObjRight = false; foreach ($objects as $object) { if ($object != "." && $object != "..") { $curObjRight = checkRightsRec($dir."/".$object); if(!$curObjRight){ $right = false; } } } } return $right; } function rrmdir($dir) { if(!checkRightsRec($dir)){ return false; } if (is_dir($dir)) { $objects = scandir($dir); foreach ($objects as $object) { if ($object != "." && $object != "..") { if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object); } } reset($objects); rmdir($dir); } return true; } ---- Server IP: 69.147.83.197 Probable Submitter: 178.24.226.254 ---- Manual Page -- http://www.php.net/manual/en/function.rmdir.php Edit -- https://master.php.net/note/edit/103140 Del: integrated -- https://master.php.net/note/delete/103140/integrated Del: useless -- https://master.php.net/note/delete/103140/useless Del: bad code -- https://master.php.net/note/delete/103140/bad+code Del: spam -- https://master.php.net/note/delete/103140/spam Del: non-english -- https://master.php.net/note/delete/103140/non-english Del: in docs -- https://master.php.net/note/delete/103140/in+docs Del: other reasons-- https://master.php.net/note/delete/103140 Reject -- https://master.php.net/note/reject/103140 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#178277) next »