diff --git a/bin/jorpelu/com/Tree.class b/bin/jorpelu/com/Tree.class index 1fd8821..4748537 100644 Binary files a/bin/jorpelu/com/Tree.class and b/bin/jorpelu/com/Tree.class differ diff --git a/src/jorpelu/com/Tree.java b/src/jorpelu/com/Tree.java index 1f9553c..6a6b367 100644 --- a/src/jorpelu/com/Tree.java +++ b/src/jorpelu/com/Tree.java @@ -1,31 +1,27 @@ package jorpelu.com; - import java.io.File; +import java.io.IOException; public class Tree { - - public static void main(String[] args) { - String ruta="."; - if (args.length>=1) ruta = args[0]; - File fich = new File(ruta); - if(!fich.exists()) { - System.out.println("No exite "+ruta); - } else { - if(fich.isFile()) { - System.out.println(ruta+" es un fichero"); - } else { - System.out.println(ruta+" es un directorio"); - File[] ficheros=fich.listFiles(); - for (File f:ficheros) { - String textoDescr = f.isDirectory() ? "/" : - f.isFile() ? "_" : "?"; - System.out.println("("+textoDescr+") "+f.getName()); - - } - } - } - - } + + public static void main(String[] args) throws IOException { + printFile(new File("."), ""); + } + + public static void printFile(File f, String spaces) { + + System.out.println(spaces.concat(File.separator).concat(f.getName())); + if (f.isDirectory() && f.canRead()) { + + for (File file : f.listFiles()) { + System.out.print("|"); + printFile(file, spaces.concat("__")); + } + } + + } + + }