From 1f069e41e259f01ab1d5036d9676ed8ceddf4d3d Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Thu, 3 Feb 2011 17:30:55 +0100 Subject: [PATCH] Added listFiles() function --- public_html/includes/functions.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/public_html/includes/functions.php b/public_html/includes/functions.php index 9bed394a..5dd7a0f8 100644 --- a/public_html/includes/functions.php +++ b/public_html/includes/functions.php @@ -557,4 +557,27 @@ function LSdebugDefined() { ); } + /** + * List files in a directory corresponding to a regex + * + * @param[in] $dir The path of the directory + * @param[in] $regex The regex apply on filename + * + * @retval array() List of file name + **/ + function listFiles($dir,$regex) { + $retval=array(); + if (is_dir($dir)) { + $d = dir($dir); + while (false !== ($file = $d->read())) { + if (is_file("$dir/$file")) { + if (preg_match($regex,$file)) { + $retval[]=$file; + } + } + } + } + return $retval; + } + ?>