<?php

/*
* Sample function to recursively return all files within a directory.
* http://www.pgregg.com/projects/php/code/recursive_readdir.phps
* Author: Paul Gregg
* http://www.pgregg.com
*
* For a more robust and featureful recursive directory listing tool
* have a look at preg_find:
* http://www.pgregg.com/projects/php/preg_find/preg_find.phps
* Example uses: http://www.pgregg.com/forums/viewtopic.php?tid=73
*/

Function listdir($start_dir='.') {

$files = array();
if (
is_dir($start_dir)) {
$fh = opendir($start_dir);
while ((
$file = readdir($fh)) !== false) {
# loop through the files, skipping . and .., and recursing if necessary
if (strcmp($file, '.')==0 || strcmp($file, '..')==0) continue;
$filepath = $start_dir . '/' . $file;
if (
is_dir($filepath) )
$files = array_merge($files, listdir($filepath));
else
array_push($files, $filepath);
}
closedir($fh);
} else {
# false if the function was called with an invalid non-directory argument
$files = false;
}

return
$files;

}

$files = listdir('.');
print_r($files);
?>

AltStyle によって変換されたページ (->オリジナル) /