2009-03-06 03:20:46 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* ls(dir,pattern) return file list in "dir" folder matching "pattern"
|
|
|
|
* ls("path","module.php?") search into "path" folder for module.php3, module.php4, ...
|
|
|
|
* ls("images/","*.jpg") search into "images" folder for JPG images
*/
|
|
|
|
class mydir{
|
|
|
|
private $list;
|
|
|
|
function __construct($__dir="./",$__pattern="*.*")
|
|
|
|
{
|
|
|
|
settype($__dir,"string");
|
|
|
|
settype($__pattern,"string");
|
|
|
|
|
|
|
|
$this->list=array();
|
|
|
|
$__regexp=preg_quote($__pattern,"/");
|
|
|
|
$__regexp=preg_replace("/[\\x5C][\x2A]/",".*",$__regexp);
|
|
|
|
$__regexp=preg_replace("/[\\x5C][\x3F]/",".", $__regexp);
|
|
|
|
|
|
|
|
if(is_dir($__dir))
|
|
|
|
if(($__dir_h=@opendir($__dir))!==FALSE)
|
|
|
|
{
|
|
|
|
while(($__file=readdir($__dir_h))!==FALSE)
|
|
|
|
if(preg_match("/^".$__regexp."$/",$__file))
|
|
|
|
array_push($this->list,$__file);
|
|
|
|
|
|
|
|
closedir($__dir_h);
|
|
|
|
sort($this->list,SORT_STRING);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function toArray()
|
|
|
|
{
|
|
|
|
return $this->list;
|
|
|
|
}
|
|
|
|
function getLast()
|
|
|
|
{
|
|
|
|
return $this->list[count($this->list)-1];
|
2012-10-31 03:39:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function array_flat($array)
|
|
|
|
{
|
|
|
|
foreach($array as $a)
|
|
|
|
{
|
|
|
|
if(is_array($a))
|
|
|
|
{
|
|
|
|
$tmp = array_merge($tmp, $this->array_flat($a));
|
|
|
|
}else {
|
|
|
|
$tmp[] = $a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $tmp;
|
2009-03-06 03:20:46 +00:00
|
|
|
}
|
2012-10-31 03:39:39 +00:00
|
|
|
|
|
|
|
function recursive($dir)
|
|
|
|
{
|
|
|
|
$files = array();
|
|
|
|
if ($handle = opendir($dir))
|
|
|
|
{
|
|
|
|
while (false !== ($file = readdir($handle)))
|
|
|
|
{
|
|
|
|
if ($file != "." && $file != "..")
|
|
|
|
{
|
|
|
|
if(is_dir($dir.'/'.$file))
|
|
|
|
{
|
|
|
|
$dir2 = $dir.'/'.$file;
|
|
|
|
$files[]=$dir2.'/';
|
|
|
|
$files[] = $this->recursive($dir2);
|
|
|
|
} else {
|
|
|
|
$files[] = $dir.'/'.$file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir($handle);
|
|
|
|
}
|
|
|
|
return $this->array_flat($files);
|
|
|
|
}
|
2009-03-06 03:20:46 +00:00
|
|
|
}
|