SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict hurricanedan's Avatar
    Join Date
    Feb 2006
    Location
    North Carolina
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    List of files in a directory

    I am trying to find all of the files in a directory and have managed to do so but I need to exclude any files that are not PDFs.

    Any idea as to how to do a filter for particular file extension?

    Thanks,

    Dan

  2. #2
    Resident Code Monkey Chris Corbyn's Avatar
    Join Date
    Nov 2005
    Location
    Melbourne, Australia
    Posts
    713
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $handle opendir($path);
    while (
    $file readdir($handle))
    {
        if (
    substr($file, -3) != 'pdf') continue;
        echo 
    $file."<br />\n";
    }
    closedir($handle); 

  3. #3
    SitePoint Addict hurricanedan's Avatar
    Join Date
    Feb 2006
    Location
    North Carolina
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Much appreciated!

  4. #4
    SitePoint Evangelist
    Join Date
    Jan 2005
    Posts
    502
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    or try using glob()

    PHP Code:
    $pdfs glob("*.pdf"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •