@SrWebDeveloperJan 28.2010 — #Seems overly complicated for something that can be done with a single function call...[/quote]
I agree. It seems glob() has been around since 4.3.0 and is a killer function, but many people continue to use the other methods. I know when I first saw the command in a function listing by name only, I assumed it tied into a wacky database type i.e. blob's and clob's! Funky name until I realized it's like a libc function. It really does save effort using it, plus any time a language construct or function can do it why not use it?
@MindzaiJan 28.2010 — #It's been around as a unix program for a long time as well, so I'm surprised more people aren't aware of it, but as you say most code examples you see use the readdir approach. It's quite rare that I ever use readdir, glob is just so much cleaner.
@dk_zero-coolJan 28.2010 — #Well. I would think that the reason people use the readdir instead of glob, is the same reason that people don't use preg_split and preg_replace if it can be done with explode and str_replace.
@NogDogJan 28.2010 — #Just a tip: if you only want the file names (no path info), you can change to the directory before doing the glob(). [code=php] $cwd = getcwd(); if(chdir('path/to/files')) { $dirs = glob(*, GLOB_ONLYDIR); chdir($cwd); } [/code] While it's no longer a one-liner, it still avoids having to do any looping in the script.