As I mentioned before, the last two methods that I’ll cover in this tutorial are “getPath()” and “getPathName().” The first one, as the name suggests, returns the path of the selected directory, while the second one retrieves the path and filename of the current directory element. Regarding the first method, here’s an example of how to use it. Check it out: $dirProc=new DirectoryIterator('default_path/'); As you can see, whether the current element being traversed is a file or a directory, the value returned by the “getPath()” method is the same. This fact is clearly demonstrated by the below results: Path of current directory is : default_path Now that you understand how the “getPath()” method works, turn your attention to the next one, that is “getPathName(),” which returns slightly more detailed information about the current directory entry. A possible implementation for this method can be seen below: $dirProc=new DirectoryIterator('default_path/'); Logically, the previous script outputs the following values for each directory element: Path of current directory is : default_path/. Okay, after covering some of the most relevant methods included with the “DirectoryIterator” class, probably you’ll have realized its awesome capabilities for dealing with timestamps, paths and index nodes. If you’re currently developing PHP applications that do a lot of work with directories, then consider including this class in your toolbox. To wrap up In this second article of the series, I took an in-depth look at some helpful methods packaged with the “DirectoryIterator” class that can help you obtain information on timestamps, paths and index nodes of directory entries However, there’s a few more methods worth covering with reference to this class in particular, thus in the last article, I’ll be explaining them, of course accompanied by copious hands-on examples. Meet you in the last part!
blog comments powered by Disqus |