function get_files($dir, $pre = '', $excluded = '') {
$result = array();
$excluded = empty($excluded)
? array('.'.DIRECTORY_SEPARATOR, '..'.DIRECTORY_SEPARATOR)
: (array)$excluded;
if ( is_dir($dir) ) {
if ( $dh = opendir($dir) ) {
while ( ($file = readdir($dh)) !== FALSE ) {
if ( is_dir($dir.$file) ) {
$file .= DIRECTORY_SEPARATOR;
if ( !(in_array($file, $excluded) || in_array($pre.$file, $excluded)) ) {
$result = array_merge($result, get_files($dir.$file, $pre.$file, $excluded));
}
} else if ( !(in_array($file, $excluded) || in_array($pre.$file, $excluded)) ) {
$result[] = $pre.$file;
}
}
closedir($dh);
}
}
return $result;
}
$files = get_files('/path/to/');
コメントを残す