HomePHP Finding Paths, Timestamps and More with the DirectoryIterator Class in PHP
Finding Paths, Timestamps and More with the DirectoryIterator Class in PHP
Are you interested in having at your disposal a quick reference for working with the “DirectoryIterator” class that comes with PHP 5? Then this might be the article that you’ve been waiting for! Welcome to the second tutorial of the series “A Close Look at the DirectoryIterator Class in PHP 5.” Over the course of this set of installments, you’ll find complete coverage of the most important methods bundled with this class, and learn how to take advantage of their excellent functionality.
If you’ve read the previous article, you probably have a better idea now of how the “DirectoryIterator” class does its business. As you’ll certainly remember, all the code samples that were shown in that article were aimed at demonstrating how easy this class makes it to traverse a specified directory.
Having at hand such a useful piece of code, there’s no need to create custom classes to deal with the contents of any directory, since the mentioned class can traverse a directory by using a regular “foreach” loop. In addition, the class on its own comes packaged with a bunch of handy methods which can be used for moving the iterator’s pointer back and forward, as well as obtaining complete information on the size, type, paths, etc. of the files contained within the selected directory.
If the wealth of impressive features exposed by this class isn’t enough for you, I have still more material to show you in the next few lines. Now that I have your attention, in this second part of the series I’ll continue exploring new methods that come with the “DirectoryIterator” class, including those that use additional capabilities to determine the full path and name of directory elements, their modification timestamps, and much more.
Having established the goals of this article, it’s time to jump forward and keep learning more about the “DirectoryIterator” class. Let’s get going!