diff --git a/file.php b/file.php index c29c11a..5e7050b 100644 --- a/file.php +++ b/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