From b8a46e14d7e9fa6f4658c122c9aa765443a48993 Mon Sep 17 00:00:00 2001 From: phpnut Date: Wed, 13 Dec 2006 04:39:26 +0000 Subject: [PATCH] Adding Folder::rmdir(). Removed empty lines from basics file git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4101 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/basics.php | 4 ++-- cake/libs/folder.php | 37 ++++++++++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/cake/basics.php b/cake/basics.php index 83b379908..1a562832a 100644 --- a/cake/basics.php +++ b/cake/basics.php @@ -1217,11 +1217,11 @@ if (!function_exists('array_diff_key')) { function array_diff_key() { $valuesDiff = array(); - + if (func_num_args() < 2) { return false; } - + foreach (func_get_args() as $param) { if (!is_array($param)) { return false; diff --git a/cake/libs/folder.php b/cake/libs/folder.php index 13943bab8..f5af4f9f3 100644 --- a/cake/libs/folder.php +++ b/cake/libs/folder.php @@ -117,7 +117,7 @@ class Folder extends Object{ sort ($files); } closedir ($dir); - } + } return array($dirs,$files); } /** @@ -164,7 +164,7 @@ class Folder extends Object{ */ function _findRecursive($pattern) { list($dirs, $files) = $this->ls(); - + $found = array(); foreach($files as $file) { if (preg_match("/^{$pattern}$/i", $file)) { @@ -281,9 +281,9 @@ function slashTerm($path) { trigger_error('chmodr() File exists', E_USER_WARNING); return false; } - + $nextPathname = substr($pathname, 0, strrpos($pathname, DS)); - + if ($this->chmodr($nextPathname, $mode)) { if(file_exists($pathname)) { umask (0); @@ -292,7 +292,7 @@ function slashTerm($path) { } } return true; - } + } /** * Create a directory structure recursively. * @@ -352,5 +352,32 @@ function slashTerm($path) { } return $size; } +/** + * Recursively Remove directories if system allow. + * + * @param string $path + * @return boolean + */ + function rmdir($path) { + if (substr($path, -1, 1) != "/") { + $path .= "/"; + } + foreach (glob($path . "*") as $file) { + if (is_file($file) === true) { + @unlink($file); + } + elseif (is_dir($file) === true) { + if($this->rmdir($file) === false) { + return false; + } + } + } + if (is_dir($path) === true) { + if(rmdir($path) === false) { + return false; + } + } + return true; + } } ?> \ No newline at end of file