From: Tim Düsterhus Date: Sat, 16 Jul 2011 14:42:23 +0000 (+0200) Subject: You can now specify a pattern for the files, that should be returned X-Git-Tag: 2.0.0_Beta_1~2012^2~3 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=8cb341a6ca5dd3789047461a11d6d7d091e3b364;p=GitHub%2FWoltLab%2FWCF.git You can now specify a pattern for the files, that should be returned --- 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); }