file : add glob method
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3340 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
28
file.php
28
file.php
@@ -234,6 +234,34 @@ class file
|
||||
return $this->cwd;
|
||||
}
|
||||
|
||||
/** Find pathnames matching a pattern
|
||||
* If there is some unreadable files, skip them quietly
|
||||
* @param string $pattern The pattern to found
|
||||
* @param integer|null $flags The additional flags
|
||||
* @return array Return an array if there is an error
|
||||
* @throws If parent directory not exists, or is not executable
|
||||
* or if there is one file unreadable
|
||||
*/
|
||||
public function glob ($pattern, $flags=0)
|
||||
{
|
||||
$this->debug (2, "glob ($pattern, $flags)");
|
||||
$this->checkPathRO ($this->baseDir);
|
||||
if (substr ($pattern, 0, 1) === "/")
|
||||
$relative = 0;
|
||||
else
|
||||
$relative = 1;
|
||||
$pattern = $this->realpath ($pattern);
|
||||
$files = glob ($pattern, $flags);
|
||||
if ($files === false)
|
||||
// FIXME : In the exception : how found the file which is not readable ?
|
||||
throw new \Exception ("Glob : can't read some files", 500);
|
||||
foreach ($files as &$file)
|
||||
{
|
||||
$file = substr ($file, strlen ($this->baseDir)+$relative);
|
||||
}
|
||||
return $files;
|
||||
}
|
||||
|
||||
/** Tells whether the given filename is a directory
|
||||
* @param string $filename The filename to test
|
||||
* @return bool true if the $filename is a directory and exists, false
|
||||
|
||||
Reference in New Issue
Block a user