Voting

: eight minus six?
(Example: nine)

The Note You're Voting On

(Qube#php@Efnet)
18 years ago
<?php

// Sample function to recursively return all files within a directory.
// http://www.pgregg.com/projects/php/code/recursive_readdir.phps

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);
?>

<< Back to user notes page

To Top