Re: something like grep



..oO(Jeff)

Michael Fesser wrote:
.oO(petersprc)

You can use the opendir and readdir functions to traverse a directory
tree. There's an example in the doc at php.net/opendir.

Or use the various iterators of the SPL. They make it quite convenient
to loop through a directory and all that's beneath it if necessary.

Having just now looked at this, I can see how this might work (It
seems to have some of the file system operators I'm familiar with). But
the documentation is poor and I'm not sure where I would even start.

Do you have any sample code for this?

To conveniently loop through an entire directory tree $path you would
need two iterators, like this:

$path = '/foo/bar/whatever';
$di = new RecursiveDirectoryIterator($path);
foreach (new RecursiveIteratorIterator($di) as $item) {
if ($item->isFile()) {
...
}
}

Of course this doesn't pay attention to the actual directory or nesting
level, it simply loops through _all_ found entries and sub entries.

See <http://www.php.net/~helly/php/ext/spl/classSplFileInfo.html> for
the various methods you can call on such file objects (just scroll down
a bit to "Public Member Functions").

Micha
.



Relevant Pages

  • Re: something like grep
    ... Or use the various iterators of the SPL. ... to loop through a directory and all that's beneath it if necessary. ... But the documentation is poor and I'm not sure where I would even start. ... it simply loops through _all_ found entries and sub entries. ...
    (comp.lang.php)
  • Re: something like grep
    ... tree. ... Or use the various iterators of the SPL. ... to loop through a directory and all that's beneath it if necessary. ...
    (comp.lang.php)
  • Re: Is There a Java Class for this Kind of Data Structure?
    ... They can be affected by uncles/aunts, but NOT by siblings. ... I was looking into a tree because I thought that would be the easiest way to ... who in turn notify their dependents and so on. ... Right now I'm experimenting with a loop that I wouldn't actually label as ...
    (comp.lang.java.programmer)
  • Looping Through All Nodes In A VB.NET Tree View And Highlighting Them.
    ... highlight them as the loop is active. ... I have a function in my application that builds a tree view. ... populates the tree view with parent nodes. ... I now have a tree view with parent and children nodes. ...
    (microsoft.public.dotnet.languages.vb.controls)
  • Re: The Collatz discrete primes!
    ... doubling outside the loop. ... longer on the counter example tree than on the regular tree. ... example being pure or impure but my thought is that the ... smallest odd integer in the counter example path would have ...
    (sci.math)