From 8cb341a6ca5dd3789047461a11d6d7d091e3b364 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Sat, 16 Jul 2011 16:42:23 +0200 Subject: [PATCH] You can now specify a pattern for the files, that should be returned --- .../files/lib/util/DirectoryUtil.class.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/wcfsetup/install/files/lib/util/DirectoryUtil.class.php b/wcfsetup/install/files/lib/util/DirectoryUtil.class.php index f0989b67bd..0255e4d011 100644 --- a/wcfsetup/install/files/lib/util/DirectoryUtil.class.php +++ b/wcfsetup/install/files/lib/util/DirectoryUtil.class.php @@ -167,11 +167,18 @@ class DirectoryUtil { * @param integer $order sort-order * @return array */ - public function getFiles($order = SORT_ASC) { + public function getFiles($order = SORT_ASC, $pattern = '') { // scan the folder $this->scanFiles(); $files = $this->files; + // sort out non matching files + if (!empty($pattern)) { + foreach ($files as $filename => $value) { + if (!preg_match($pattern, $filename)) unset($files[$filename]); + } + } + if ($order == SORT_DESC) { krsort($files, $order); } @@ -194,11 +201,18 @@ class DirectoryUtil { * @param integer $order sort-order * @return array */ - public function getFilesObj($order = SORT_ASC) { + public function getFilesObj($order = SORT_ASC, $pattern = '') { // scan the folder $this->scanFilesObj(); $objects = $this->filesObj; + // sort out non matching files + if (!empty($pattern)) { + foreach ($objects as $filename => $value) { + if (!preg_match($pattern, $filename)) unset($objects[$filename]); + } + } + if ($order == SORT_DESC) { krsort($objects, $order); } -- 2.20.1