Re: something like grep
- From: Michael Fesser <netizen@xxxxxx>
- Date: Wed, 30 Jul 2008 03:15:44 +0200
..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
.
- Follow-Ups:
- Re: something like grep
- From: Jeff
- 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
- something like grep
- Prev by Date: Re: Working more efficiently in PHP
- Next by Date: cheapestsell@hotmail.com sell cheap NHL NFL MITCHELL NFL PRO BOWL&SUPER NBA NBA children MLB NBA jerseys t-shirt shorts
- Previous by thread: Re: something like grep
- Next by thread: Re: something like grep
- Index(es):
Relevant Pages
|