Lista el contenido de un carpeta o directorio con función de recursividad. La recursividad consiste en generar un listado de forma automática de todas las subcarpetas y ficheros hasta que finalice el árbol de carpetas.
/**
* @desc Añadir un nuevo Usuario
* la nomenclatura de funciones es para simular un poco la POO
* ya que en PHP4 no se puede utilizar
*/
function listDirectory( $path = '.', $level = 0 ){
// Directories to ignore when listing output.
$ignore = array( '.', '..' );
// Open the directory to the handle $dh
$dh = @opendir( $path );
// Loop through the directory
while( false !== ( $file = readdir( $dh ) ) ){
// Check that this file is not to be ignored
if( !in_array( $file, $ignore ) ){
// Indent spacing for better view
$spaces = str_repeat( ' ', ( $level * 5 ) );
// Show directories only
if(is_dir( "$path/$file" ) ){
// Re-call this same function but on a new directory.
// this is what makes function recursive.
echo "$spaces$file";
listDirectory( "$path/$file", ($level+1) );
}
}
}
// Close the directory handle
closedir( $dh );
}
Folder,Directory,Carpeta,Archivos,Listar

