RecursiveDirectoryIterator & RecursiveFilterIterator

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux