Entry
How can I get all file names stored in a directory tree?
How can I recursively get the name and size of all files in a directory and it's subdirectories?
Aug 10th, 1999 11:00
Nathan Wallace, Robert Aden
I guess something like this would work. This functions returns the files
and size of them in the form file1=size&file2=size2 so it needs some
modification to just list them.
function sizeDirectory($directory) {
$dirhandle = opendir($directory);
while ( $entity = readdir($dirhandle)) {
if ($entity[0] == '.') {
// Do nutting unless dotfiles should count
} elseif ( is_dir($directory . '/' . $entity)) {
$ret .= sizeDirectory($directory . '/' . $entity);
} else {
$ret .= '&' . urlencode($entity) . '=' . (filesize($directory .
'/' . $entity));
}
}
return $ret;
}