List all files in a directory, and in sub directory's, return as array.
This is one of the most useful function I have made. Please, add your own!
<?php
php
function get_dir_structure($path, $recursive = true) {
if (is_dir($path)) {
if ($handle = opendir($path)) {
while (false !== ($item = readdir($handle))) {
if ($item != '.' && $item != '..') {
if (is_dir($path . $item)) {
if ($recursive) {
$return[$item] = get_dir_structure($path . $item . '/');
} else {
$return[$item] = array();
}
} else {
$return[] = $item;
}
}
}
closedir($handle);
}
return $return;
} else {
trigger_error('$path is not a directory!', E_USER_WARNING);
return FALSE;
}
}
print_r(get_dir_structure('/home/dygear/My Music/'));
?>