note 68178 deleted from function.rmdir by nlopess

From: Date: Mon, 14 Aug 2006 20:28:27 +0000
Subject: note 68178 deleted from function.rmdir by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-115906@lists.php.net to get a copy of this message
Note Submitter: itportal at gmail dot com ---- This is a the same func with a simple addition - it doesn't matter if the directory ends with a slash ("/") or not: function remove_directory($dir) { if(substr($dir, -1, 1) == "/"){ $dir = substr($dir, 0, strlen($dir) - 1); } if ($handle = opendir("$dir")) { while (false !== ($item = readdir($handle))) { if ($item != "." && $item != "..") { if (is_dir("$dir/$item")) { remove_directory("$dir/$item"); } else { unlink("$dir/$item"); } } } closedir($handle); rmdir($dir); } }

« previous php.notes (#115906) next »