From 78822d42a40735eae4b0c7b1e847dca9c99dfbe8 Mon Sep 17 00:00:00 2001 From: w2xi <43wangxi@gmail.com> Date: Fri, 18 Jun 2021 21:05:30 +0800 Subject: [PATCH] Modify 'deleteRecursively' method of 'Directory' class --- src/Directory.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Directory.php b/src/Directory.php index 3861363..1be72ad 100644 --- a/src/Directory.php +++ b/src/Directory.php @@ -83,14 +83,16 @@ public function createRecursively($mode = null) { /** * Attempts to delete the directory including any contents recursively + * + * @param string the path of the directory to be removed */ - public function deleteRecursively() { - if ($this->exists()) { - $entries = @\scandir($this->path); + public function deleteRecursively($path) { + if ( is_dir($path) ) { + $entries = @\scandir($path); foreach ($entries as $entry) { if ($entry !== '.' && $entry !== '..') { - $entryPath = $this->path . '/' . $entry; + $entryPath = $path . '/' . $entry; if (@\is_dir($entryPath)) { $this->deleteRecursively($entryPath); @@ -101,7 +103,7 @@ public function deleteRecursively() { } } - @\rmdir($this->path); + @\rmdir($path); } }