You can now specify a pattern for the files, that should be returned
authorTim Düsterhus <timwolla@arcor.de>
Sat, 16 Jul 2011 14:42:23 +0000 (16:42 +0200)
committerTim Düsterhus <timwolla@arcor.de>
Sat, 16 Jul 2011 14:43:58 +0000 (16:43 +0200)
wcfsetup/install/files/lib/util/DirectoryUtil.class.php

index f0989b67bd1ef3160cb51923e27adeb5c396c534..0255e4d01131bfc0bf815990e2dabd9e1e5ac6ac 100644 (file)
@@ -167,11 +167,18 @@ class DirectoryUtil {
         * @param       integer         $order  sort-order
         * @return      array<string>
         */
-       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<DirectoryIterator>
         */
-       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);
                }