Monday, May 25, 2009

Simple function to read directory contents


/*
** Function: dir_list (PHP)
** Desc: Simple function to read directory contents
** Example: dir_list('data/');
** Author: Jonas John
*/

function dir_list($path){

$files = array();

if (is_dir($path)){
$handle = opendir($path);
while ($file = readdir($handle)) {
if ($file[0] == '.'){ continue; }

if (is_file($path.$file)){
$files[] = $file;
}
}
closedir($handle);
sort($files);
}

return $files;

}
?>

No comments: