Re: Getting the filenames from a folder
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

Re: Getting the filenames from a folder

From: Chung Leong <chernyshevsky@hotmail.com>
Date: Mon Oct 31 2005 - 06:14:16 CET

juglesh wrote:
> Chung Leong wrote:
> > I usually use glob() 'cause I'm lazy.
> >
> > http://fi.php.net/glob/
>
> nice, i never saw that. I assume you could go *.*, can you give it
> multiple matches, like *.jpg, *.gif ?

Yes, if you pass the GLOB_BRACE flag.

Example:

$images = glob("*.{jpeg,jpg,gif,png}", GLOB_BRACE);

You can also character class matching with glob():

$images = glob("[ab]*.gif"); // gif files starting with letter a or b

And wildcards work for sub-folder as well:

$images = glob("*/*.gif"); // gif files in all sub-folders

A real time-saver. One downside though is that the function is broken
in some versions on Win32.
Received on Mon Nov 21 02:53:19 2005