SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Sep 2012
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Check if a file folder contains certain extensions

    Hello. I was wondering if anyone can help me with the following programming concern.

    Using php. Does anyone know how to scan a folder located on a server; Seeing if the folder contains files of a specific file type. Namely, If I wanted to search for all the files in a folder with a *.jpg extension. USING IF / ELSE structure. IF the file(s) are found echo" JPG files exist" ELSE echo"No files containing such extensions exist."

    Thanking you

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,122
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Sounds like a homework assignment, but the interested operations you want to use are opendir, readdir, and then check the name of the file returned by readdir to see if the extension you are looking for exists.

    Once you have some code written, post back if you need more help.

  3. #3
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  4. #4
    SitePoint Member
    Join Date
    Sep 2012
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    Sounds like a homework assignment, but the interested operations you want to use are opendir, readdir, and then check the name of the file returned by readdir to see if the extension you are looking for exisot a ts.

    Once you have some code written, post back if you need more help.

    Not a homework question. Far from it. But will keep you posted. Thanks.

  5. #5
    SitePoint Addict kduv's Avatar
    Join Date
    May 2012
    Location
    Maui, HI
    Posts
    211
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Using a combination of scandir(), substr(), and a foreach loop can get it done pretty quickly and easily.
    Keith
    Freelance web developer
    http://www.duvalltech.com/


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
  •