News Feed
Sections




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

Fabien Potencier's Blog:
Find your Files
April 22, 2010 @ 14:45:09

Fabien Potencier has a new post today about an update he's made to an aging bit of code for the Symfony framework to find files on the local filesystem - sfFinder.

I used the opendir, readdir, and closedir native PHP functions, and it did the job quite well. The PHP class was named sfFinder, and it can still be found in all symfony versions. Even if the class is bundled with symfony, I know that a few people use it for all kind of stuff, not necessarily related to symfony. But the code starts to show its age; first because I learned a lot since then about PHP, and also because there is a better way now. Enter iterators!

He shows an example of how to use Iterators to search through directories recursively (RecursiveDirectoryIterator) and locate a certain filename. He also looks at making it more OOP and including filtering to remove files from the search. He's packaged up some of this logic into a new Symfony component - the Finder component - that can be used to locate files in a path, be restricted to a depth for the search, match regular expressions file names, filter by file size and much more.

If you'd like to dig into the code, check out this page on github for this new component (PHP 5.3 only).

1 comment voice your opinion now!
find file symfony component finder iterator


blog comments powered by Disqus

Similar Posts

Nikita Popov's Blog: A plea for less (XML) configuration files

Matthew Weir O'Phinney's Blog: Zend_Layout and Zend_View Enhanced components now in core

Noupe.com: 20 Useful PHP + jQuery Components & Tuts for Everyday Project

Jake Smith's Blog: Callback Filter Iterator in PHP 5.3/5.4

Zend Developer Zone: Announcing the Apache Solr extension in PHP


Community Events





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


laravel series framework interview language library deployment update unittest package tips install community zendserver release symfony introduction opinion podcast api

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