summaryrefslogtreecommitdiff
path: root/ext/spl/examples/findfile.php
blob: 68c0e0dd65f805b6454aee581bcfab059d589f7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php

/** Find a specific file by name.
 *
 * Usage: php findfile.php <path> <name>
 *
 * <path>  Path to search in.
 * <name>  Filename to look for.
 *
 * (c) Marcus Boerger, 2003
 */

if ($argc < 3) {
	echo <<<EOF
Usage: php findfile.php <file> <name>

Find a specific file by name.

<path>  Path to search in.
<name>  Filename to look for.


EOF;
	exit(1);
}

class FindFile extends FilterIterator
{
	protected $file;

	function __construct($path, $file) {
		$this->file = $file;
		parent::__construct(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)));
	}
	function accept() {
		return !strcmp($this->current(), $this->file);
	}
}

foreach(new FindFile($argv[1], $argv[2]) as $pathname => $file) echo $file->getPathname()."\n";
?>