|
Posted by "Jared Williams" on 11/26/05 23:04
Hi,
Having trouble writing a RecursiveFilterIterator to exclude linked directories from the recursive listing..
class DXLinkDirectoryRecursiveFilter extends RecursiveFilterIterator
{
function accept() { return TRUE; }
}
interface DXDirectoryVisitor
{
function visit(DirectoryIterator $file);
}
class DXDirectory
{
const FILES_FIRST = RecursiveIteratorIterator::CHILD_FIRST;
const FILES_ONLY = RecursiveIteratorIterator::LEAVES_ONLY;
const DIR_FIRST = RecursiveIteratorIterator::SELF_FIRST;
private $directory;
function __construct($directory)
{
$this->directory = $directory;
}
function forEvery(DXDirectoryVisitor $visitor, $mode = self::DIR_FIRST)
{
$r = file_exists($this->directory);
if ($r)
{
$directoryIterator = new RecursiveDirectoryIterator($this->directory);
$directoryIterator = new DXLinkDirectoryRecursiveFilter($directoryIterator);
$recursiveIteratorIterator = new RecursiveIteratorIterator($directoryIterator, $mode);
foreach($recursiveIteratorIterator as $i)
{
if (!$i->isDot())
$r = $r && $visitor->visit($i);
}
}
return $r;
}
}
class DXDirEcho implements DXDirectoryVisitor
{
function visit(DirectoryIterator $dir)
{
echo $dir->getPathname(), "\n";
return TRUE;
}
}
$d = new DXDirectory('somedirectory');
$d->forEvery(new DXDirEcho());
The filter shouldn't be doing anything, according to my understanding, but its filtering out all files in any of the subdirectories.
Jared
Navigation:
[Reply to this message]
|