From d07ff69ffbf2c5c92bed7e4d2c3d16a142322d11 Mon Sep 17 00:00:00 2001 From: ToMtOm Date: Wed, 4 Sep 2024 17:47:28 +0200 Subject: [PATCH] ADD deleteDirectory --- src/tomitomasEqLogicTrait.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/tomitomasEqLogicTrait.php b/src/tomitomasEqLogicTrait.php index 3bd92d6..b64788d 100644 --- a/src/tomitomasEqLogicTrait.php +++ b/src/tomitomasEqLogicTrait.php @@ -167,6 +167,29 @@ public static function backupExclude() { ]; } + public static function deleteDirectory($dir) { + if (!file_exists($dir)) { + return false; + } + + if (!is_dir($dir)) { + return false; + } + + $items = array_diff(scandir($dir), array('.', '..')); + + foreach ($items as $item) { + $path = $dir . DIRECTORY_SEPARATOR . $item; + + if (is_dir($path)) { + self::deleteDirectory($path); + } else { + unlink($path); + } + } + + return rmdir($dir); + } /******************************* * From @Mips2648