]> granicus.if.org Git - php/commitdiff
Update examples
authorMarcus Boerger <helly@php.net>
Sun, 25 Jan 2004 13:03:24 +0000 (13:03 +0000)
committerMarcus Boerger <helly@php.net>
Sun, 25 Jan 2004 13:03:24 +0000 (13:03 +0000)
ext/spl/examples/findfile.inc [new file with mode: 0755]
ext/spl/examples/findfile.php
ext/spl/examples/findregex.php [new file with mode: 0755]

diff --git a/ext/spl/examples/findfile.inc b/ext/spl/examples/findfile.inc
new file mode 100755 (executable)
index 0000000..e0c685b
--- /dev/null
@@ -0,0 +1,25 @@
+<?php
+
+/**
+ * @brief   Base class to find files
+ * @author  Marcus Boerger
+ * @version 1.0
+ *
+ */
+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);
+       }
+}
+
+?>
\ No newline at end of file
index 68c0e0dd65f805b6454aee581bcfab059d589f7e..0622c4e3d77eaf3a25886ffdacc5511ba349b24f 100755 (executable)
@@ -24,18 +24,5 @@ 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";
+foreach(new FindFile($argv[1], $argv[2]) as $file) echo $file->getPathname()."\n";
 ?>
\ No newline at end of file
diff --git a/ext/spl/examples/findregex.php b/ext/spl/examples/findregex.php
new file mode 100755 (executable)
index 0000000..faed6a8
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+       
+/** Find a specific file by name.
+ *
+ * Usage: php findregex.php <path> <name>
+ *
+ * <path>  Path to search in.
+ * <name>  Filename to look for.
+ *
+ * (c) Marcus Boerger, Adam Trachtenberg, 2004
+ */
+
+if ($argc < 3) {
+       echo <<<EOF
+Usage: php findregex.php <file> <name>
+
+Find a specific file by name.
+
+<path>  Path to search in.
+<name>  Regex for filenames to look for.
+
+
+EOF;
+       exit(1);
+}
+
+class RegexFindFile extends FindFile
+{
+       function accept()
+       {
+               return preg_match($this->file, $this->current());
+       }
+}
+
+foreach(new RegexFindFile($argv[1], $argv[2]) as $file) {
+       echo $file->getPathname()."\n";
+}
+
+?>     
\ No newline at end of file