[thelist] PHP- get list of files in directory?

Stephen Rider evolt_org at striderweb.com
Tue Mar 13 16:56:23 CDT 2007

On Mar 13, 2007, at 9:37 AM, Stephen Rider wrote:

> Is there a way to get a list of files in a particular directory using
> PHP?  I would preferably like to end up with an array containing the
> name of each file found.

I ended up with this, which works great:

// Get array of CSS files for Style dropdown
$arrStyles = array();
if ($handle = opendir(dirname(__FILE__) . '/styles')) {
    while (false !== ($file = readdir($handle))) {
	   if ($file != '.' && $file != '..' && substr($file,1) != '.') {
			$arrStyles[] = $file;

What I'm making is a plugin for WordPress, so I want it to be as  
server-flexible as possible; thus no PHP5-only functions.  Otherwise  
scandir() would have done the job  a lot more easily.

If you're curious:
(Though what I just did is not yet integrated into what you see on  
that page....)

Stephen Rider

More information about the thelist mailing list