Permalink
Browse files

Converting internals of Folder::read() to use DirectoryIterator.

  • Loading branch information...
1 parent f94394f commit 7656feb0bb264d5f082fb7c57cedefd903ccaaeb @markstory markstory committed Aug 27, 2011
Showing with 15 additions and 11 deletions.
  1. +15 −11 lib/Cake/Utility/Folder.php
@@ -145,29 +145,33 @@ public function read($sort = true, $exceptions = false, $fullPath = false) {
}
$skipHidden = isset($exceptions['.']) || $exceptions === true;
- if (false === ($dir = @opendir($this->path))) {
+ try {
+ $iterator = new DirectoryIterator($this->path);
+ } catch (UnexpectedValueException $e) {
return array($dirs, $files);
}
- while (false !== ($item = readdir($dir))) {
- if ($item === '.' || $item === '..' || ($skipHidden && $item[0] === '.') || isset($exceptions[$item])) {
+ foreach ($iterator as $item) {
+ if ($item->isDot()) {
continue;
}
-
- $path = Folder::addPathElement($this->path, $item);
- if (is_dir($path)) {
- $dirs[] = $fullPath ? $path : $item;
+ $name = $item->getFileName();
+ if ($skipHidden && $name[0] === '.' || isset($exceptions[$name])) {
+ continue;
+ }
+ if ($fullPath) {
+ $name = $item->getPathName();
+ }
+ if ($item->isDir()) {
+ $dirs[] = $name;
} else {
- $files[] = $fullPath ? $path : $item;
+ $files[] = $name;
}
}
-
if ($sort || $this->sort) {
sort($dirs);
sort($files);
}
-
- closedir($dir);
return array($dirs, $files);
}

0 comments on commit 7656feb

Please sign in to comment.