| @ -1,31 +1,27 @@ | |||||
| package jorpelu.com; | package jorpelu.com; | ||||
| import java.io.File; | import java.io.File; | ||||
| import java.io.IOException; | |||||
| public class Tree { | 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("__")); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | } | ||||