PHP
  Home arrow PHP arrow Page 3 - Using Introspective Methods with the DirectoryIterator Class in PHP 5
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PHP

Using Introspective Methods with the DirectoryIterator Class in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 5
    2006-09-25


    Table of Contents:
  • Using Introspective Methods with the DirectoryIterator Class in PHP 5
  • The isDir() method
  • Using the isDot() method
  • Implementing the isExecutable(), isReadable() and isWritable() methods
  • The getPerms() and getType() methods

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Using Introspective Methods with the DirectoryIterator Class in PHP 5 - Using the isDot() method
    ( Page 3 of 5 )

    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
     

       

    PHP ARTICLES

    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek