Listing all files in a folder...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Chen
    Senior Member
    • Jun 2001
    • 8388

    Listing all files in a folder...

    I know how to list files in a folder:
    Code:
    $dir=dir("./$folder/.");
    while($filename=$dir->read()) {
    
    }
    $dir->close();
    but I want to only list files with the extension $extension.

    So right now I'm using this:
    Code:
    $dir=dir("./$folder/.");
    while($filename=$dir->read()) {
    	if (getextension($filename)==$extension) {
    		// Do the good stuff
    	}
    }
    $dir->close();
    (getextension() is a function from vBulletin btw)

    But I was wondering if there is an easy way to do this, straight from the dir class?

    Thanks for any help.
    Chen Avinadav
    Better to remain silent and be thought a fool than to speak out and remove all doubt.

    גם אני מאוכזב מסיקור תחרות לתור מוטור של NRG הרשת ע"י מעריב
  • Mark Hensler
    Senior Member
    • Feb 2001
    • 570

    #2
    I have a home made function as well. I've not found a PHP function to do this.

    There is, however, a filetype() function. But that only helps if your looking to weed out text files vs image files.

    Comment

    • Chen
      Senior Member
      • Jun 2001
      • 8388

      #3
      You're the 3rd PHP guru that told me I can't do this, I think that settles it.

      Thanks.
      Chen Avinadav
      Better to remain silent and be thought a fool than to speak out and remove all doubt.

      גם אני מאוכזב מסיקור תחרות לתור מוטור של NRG הרשת ע"י מעריב

      Comment

      widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
      Working...