westdc-zf1/application/models/mydir.php

37 lines
980 B
PHP
Executable File

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