From 8598721e262bf2cc40061fde45d66910319a3e81 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 3 Feb 2012 14:01:01 -0600 Subject: [PATCH] added recursive rmdir function. --- laravel/file.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/laravel/file.php b/laravel/file.php index 7466427f..f5f22268 100644 --- a/laravel/file.php +++ b/laravel/file.php @@ -241,6 +241,39 @@ public static function cpdir($source, $destination, $delete = false, $options = if ($delete) rmdir($source); } + /** + * Recursively copy directory contents to another directory. + * + * @param string $source + * @param string $destination + * @param bool $delete + * @param int $options + * @return void + */ + public static function rmdir($directory) + { + if ( ! is_dir($directory)) return; + + $items = new fIterator($directory); + + foreach ($items as $item) + { + // If the item is a directory, we can just recurse into the + // function and delete that sub-directory, otherwise we'll + // just deleete the file and keep going! + if ($item->isDir()) + { + static::rmdir($item->getRealPath()); + } + else + { + @unlink($item->getRealPath()); + } + } + + @rmdir($directory); + } + /** * Get the most recently modified file in a directory. *