Home arrow PHP arrow Page 3 - Using Introspective Methods with the DirectoryIterator Class in PHP 5

Using the isDot() method - PHP

If you’re one of those PHP developers who want to explore the package of classes that come bundled with the Standard PHP Library (SPL), then fear not, because you’re at the right place. Welcome to the concluding part of the series "A Close Look at the DirectoryIterator Class in PHP 5." In three parts, this series introduces the most important methods attached to this class, and shows you how to use them by mean of extensive hands-on examples.

TABLE OF CONTENTS:
  1. Using Introspective Methods with the DirectoryIterator Class in PHP 5
  2. The isDir() method
  3. Using the isDot() method
  4. Implementing the isExecutable(), isReadable() and isWritable() methods
  5. The getPerms() and getType() methods
By: Alejandro Gervasio
Rating: starstarstarstarstar / 5
September 25, 2006

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

The natural introspective abilities that were included with the "DirectoryIterator" class allow you, among other things, to determine whether a given directory entry is  "." or ":". This checking process can be easily performed by using the "isDot()" method, which has been utilized in the example below. Please examine its source code:

$dirProc=new DirectoryIterator('default_path/');
foreach($dirProc as $dirContent){
    if($dirContent->isDot()){
        echo 'Current element is "." or ":" and its path is the
following : '.$dirContent->getPathName().'<br />';
    }
    else{
        echo 'Current element is a regular file and it path is
the following : '.$dirContent->getPathName().'<br />';
    }
}

In this case, the above code snippet illustrates in a friendly fashion how to use the "isDot()" method, in order to determine whether the current directory element is "." or ":". Regarding the results outputted by this example, they're listed below:

Current element is "." or ":" and its path is the following : default_path/.
Current element is "." or ":" and its path is the following : default_path/..
Current element is a regular file and it path is the following : default_path/file1.txt
Current element is a regular file and it path is the following : default_path/file2.txt

Assuming that you had no major problems understanding the previous example, I'm pretty sure that you're starting to realize the great introspective capabilities natively exposed by the "DirectoryIterator" class. They're indeed remarkable!

Okay, now that you know how the "isDot()" method works, let's leap forward quickly and look at three new methods that belong to the "DirectoryIterator" class, which also use introspection to determine whether a specific directory entry is readable, writable and executable.

Sounds really interesting, right? Therefore, I recommend you read the following section to find out how the methods that I mentioned before can be put to work.



 
 
>>> More PHP Articles          >>> More By Alejandro Gervasio
 

blog comments powered by Disqus
   

PHP ARTICLES

- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 3 - Follow our Sitemap

Dev Shed Tutorial Topics: