--- /dev/null
+<?php
+
+/**
+ * @brief Iterator that iterates over several iterators one after the other
+ * @author Marcus Boerger
+ * @version 1.0
+ *
+ */
+class AppendIterator implements Iterator
+{
+ protected $iterators;
+
+ function __construct()
+ {
+ $this->iterators = new ArrayIterator();
+ }
+
+ function append(Iterator $it)
+ {
+ $this->iterators->append($it);
+ }
+
+ function getInnerIterator()
+ {
+ return $this->iterators->current();
+ }
+
+ function rewind()
+ {
+ $this->iterators->rewind();
+ }
+
+ function valid()
+ {
+ return $this->iterators->valid() && $this->getInnerIterator()->valid();
+ }
+
+ function current()
+ {
+ return $this->getInnerIterator()->current();
+ }
+
+ function key()
+ {
+ return $this->getInnerIterator()->key();
+ }
+
+ function next()
+ {
+ while($this->iterators->valid()) {
+ $this->getInnerIterator()->next();
+ if ($this->valid()) {
+ return;
+ }
+ $this->iterators->next();
+ }
+ }
+}
+
+?>
\ No newline at end of file
function __construct($path, $file)
{
$this->file = $file;
- parent::__construct(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)));
+ $list = split(';', $path);
+ if (count($list) <= 1) {
+ parent::__construct(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)));
+ } else {
+ $it = new AppendIterator();
+ foreach($list as $path) {
+ $it->append(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)));
+ }
+ parent::__construct($it);
+ }
}
function accept()
*
* Usage: php findfile.php <path> <name>
*
- * <path> Path to search in.
+ * <path> Path to search in. You can specify multiple paths by separating
+ * them with ';'.
* <name> Filename to look for.
*
- * (c) Marcus Boerger, 2003
+ * (c) Marcus Boerger, 2003 - 2004
*/
if ($argc < 3) {
echo <<<EOF
-Usage: php findfile.php <file> <name>
+Usage: php findfile.php <path> <name>
Find a specific file by name.