Reply to RecursiveDirectoryIterator & RecursiveFilterIterator

Your name:

Reply:


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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация