Added listFiles() function

This commit is contained in:
Benjamin Renard 2011-02-03 17:30:55 +01:00
parent 39401e882b
commit 1f069e41e2

View file

@ -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;
}
?> ?>