note 84377 modified in function.rmdir by danbrown

From: Date: Tue, 10 Mar 2009 19:42:08 +0000
Subject: note 84377 modified in function.rmdir by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-151702@lists.php.net to get a copy of this message
A function that deletes a dir that not empty: Returns true on success, or false on faileure. <?php function advancedRmdir($path) { //mappát töröl akkor is, ha nem üres $origipath = $path; $handler = opendir($path); while (true) { $item = readdir($handler); if ($item == "." or $item == "..") { continue; } elseif (gettype($item) == "boolean") { closedir($handler); if (!@rmdir($path)) { return false; } if ($path == $origipath) { break; } $path = substr($path, 0, strrpos($path, "/")); $handler = opendir($path); } elseif (is_dir($path."/".$item)) { closedir($handler); $path = $path."/".$item; $handler = opendir($path); } else { unlink($path."/".$item); } } return true; } ?> --was-- A function that deletes a dir that not empty: Returns true on success, or false on faileure. function advancedRmdir($path) { //mappát töröl akkor is, ha nem üres $origipath = $path; $handler = opendir($path); while (true) { $item = readdir($handler); if ($item == "." or $item == "..") { continue; } elseif (gettype($item) == "boolean") { closedir($handler); if (!@rmdir($path)) { return false; } if ($path == $origipath) { break; } $path = substr($path, 0, strrpos($path, "/")); $handler = opendir($path); } elseif (is_dir($path."/".$item)) { closedir($handler); $path = $path."/".$item; $handler = opendir($path); } else { unlink($path."/".$item); } } return true; } http://php.net/manual/en/function.rmdir.php

« previous php.notes (#151702) next »