From 6a167e99dcf1beef7cd4acb75eb3458e0bcce2d5 Mon Sep 17 00:00:00 2001 From: slawkens Date: Sat, 13 Apr 2019 03:17:01 +0200 Subject: [PATCH] Add optional parameters to deleteDirectory function ($dir, $ignore = array(), $contentOnly = false) --- system/functions.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/system/functions.php b/system/functions.php index 38a95fae..ff3404da 100644 --- a/system/functions.php +++ b/system/functions.php @@ -1032,7 +1032,7 @@ function getTopPlayers($limit = 5) { return $players; } -function deleteDirectory($dir) { +function deleteDirectory($dir, $ignore = array(), $contentOnly = false) { if(!file_exists($dir)) { return true; } @@ -1042,15 +1042,19 @@ function deleteDirectory($dir) { } foreach(scandir($dir, 0) as $item) { - if($item === '.' || $item === '..') { + if($item === '.' || $item === '..' || in_array($item, $ignore, true)) { continue; } - if(!deleteDirectory($dir . DIRECTORY_SEPARATOR . $item)) { + if(!in_array($item, $ignore, true) && !deleteDirectory($dir . DIRECTORY_SEPARATOR . $item)) { return false; } } + if($contentOnly) { + return true; + } + return rmdir($dir); }