News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Stefan Koopmanschap's Blog:
GlobIterator Easy access to specific files
April 17, 2012 @ 12:43:42

Stefan Koopmanschap has a new post to his blog showing a handy use of the GlobIterator to access only certain files.

For a project I am working on I needed to iterate over all .xml files in a specific directory. I started out with a DirectoryIterator, then considered I didn't want the XML filtering to take place inside my foreach loop. I decided to add a FilterIterator to the setup, but then felt this was not the right solution either. So I turned to my favorite SPL guru, Joshua Thijssen, to see if I was overseeing some kind of filter-option in the DirectoryIterator. I didn't, but I did oversee something else: GlobIterator.

The GlobIterator lets you use functionality similar to the glob function (including being able to use wildcards in file searching) and get the resulting list back as a set of SplFileInfo objects, complete with additional metadata that can be extracted.

0 comments voice your opinion now!
globiterator spl iterator glob filesystem find


blog comments powered by Disqus

Similar Posts

DevShed: Iterators in the Simplest Sense - An Accessible Implementation in PHP 4

php|architect: Coding Costest for Feb. 2008 - Link Finder

Jeremy Cook's Blog: Implementing the ArrayAccess Interface

Zend Developer Zone: Implementing the Observer Pattern with SplObserver and SplSubject

Jani Hartikainen's Blog: How to use built-in SPL exception classes for better error handling


Community Events





Don't see your event here?
Let us know!


install symfony2 code introduction laravel series interview developer release api language framework threedevsandamaybe community refactor list testing opinion unittest podcast

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework