2003-11-09 14:05:36 +00:00
|
|
|
<?php
|
|
|
|
|
2003-12-04 19:39:46 +00:00
|
|
|
/** 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
|
2003-11-09 14:05:36 +00:00
|
|
|
{
|
|
|
|
protected $file;
|
|
|
|
|
|
|
|
function __construct($path, $file) {
|
|
|
|
$this->file = $file;
|
2003-11-22 20:51:15 +00:00
|
|
|
parent::__construct(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)));
|
2003-11-09 14:05:36 +00:00
|
|
|
}
|
|
|
|
function accept() {
|
|
|
|
return !strcmp($this->it->current(), $this->file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach(new FindFile($argv[1], $argv[2]) as $pathname => $file) echo "$pathname\n";
|
|
|
|
?>
|