PHP
  Home arrow PHP arrow Page 3 - Finding Paths, Timestamps and More with the DirectoryIterator Class in PHP
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? 
PHP

Finding Paths, Timestamps and More with the DirectoryIterator Class in PHP
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 5
    2006-09-18


    Table of Contents:
  • Finding Paths, Timestamps and More with the DirectoryIterator Class in PHP
  • Learning the rewind(), current() and valid() methods
  • Using the getFileName() and isFile() methods
  • Using the getMTime(), getATime(), and getCTime() methods
  • Using the getPath() and getPathName() 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


    Finding Paths, Timestamps and More with the DirectoryIterator Class in PHP - Using the getFileName() and isFile() methods
    ( Page 3 of 5 )

    As I mentioned at the end of the previous section, the “DirectoryIterator” class has many more methods that can make your life much easier when it comes to processing directories and their corresponding files. In this particular situation, I’ll show you how to use two entirely new methods that belong to this class: the “getFile()” and “isFile()” methods respectively.

    In most cases, a hands-on example can be much more instructive than some boring sentences. So the use of the methods that I mentioned before is illustrated by the following script. Take a look:

    $dirProc=new DirectoryIterator('default_path/');
    foreach($dirProc as $dirContent){
        if($dirContent->isFile()){
            echo 'Name of current file is : '.$dirContent-
    >getFileName().'<br />';
        }
    }

    In this case, the example above first loops over the selected directory and checks for the files included in it by using the corresponding “isFile()” method (by the way, this is very similar to the “is_file()” PHP native function, isn’t it?), and finally displays their names by the “getFileName()” method.

    Now, after examining the logic of the previous script, and assuming that the selected “default_path” contains two files, “file1.txt” and “file2.txt” respectively, have a look at the output generated by it:

    Name of current file is : file1.txt
    Name of current file is : file2.txt

    As shown in the example you learned before, retrieving the names of the files that might be included within a specific directory is really a straightforward process that doesn’t bear a longer discussion. However, this journey isn’t over yet, since the “DirectoryIterator” class also comes packaged with an excellent set of methods, specifically to deal with timestamps of directories and files.

    That’s exactly the subject that I’ll discuss in the upcoming section, which certainly is a good reason for you to keep on reading. To learn more about these new methods, please click on the link below.



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

       

    PHP ARTICLES

    - 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
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    Stay green...Green IT