Re: something like grep
- From: Jeff <jeff@xxxxxxxxxxxxxxx>
- Date: Wed, 30 Jul 2008 19:34:55 -0400
Michael Fesser wrote:
.oO(Jeff)
Michael Fesser wrote:.oO(petersprc)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.
You can use the opendir and readdir functions to traverse a directoryOr use the various iterators of the SPL. They make it quite convenient
tree. There's an example in the doc at php.net/opendir.
to loop through a directory and all that's beneath it if necessary.
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()) {
...
}
}
Thanks,
I see that this gives an alphabetically sorted list.
/a.html
/a/a.html
/ab.html
/b.html
I find it fascinating that can be done, but not useful at the moment.
Can I look at the root first and then recurse through the directories? Or is this easier with recursive readdir?
I imagine this is possible, but I haven't a clue how to go about that. I take it this is documentation for something that has no other documentation?
Jeff
.
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
- Follow-Ups:
- Re: something like grep
- From: Michael Fesser
- Re: something like grep
- References:
- something like grep
- From: Jeff
- Re: something like grep
- From: petersprc
- Re: something like grep
- From: Michael Fesser
- Re: something like grep
- From: Jeff
- Re: something like grep
- From: Michael Fesser
- something like grep
- Prev by Date: Re: if statement in an elseif block with a preceeding exit statement
- Next by Date: Re: online users
- Previous by thread: Re: something like grep
- Next by thread: Re: something like grep
- Index(es):
Relevant Pages
|