Browse Source

Soluciono problema

master
vigliom 2 years ago
parent
commit
abe87f88e6
2 changed files with 20 additions and 24 deletions
  1. BIN
      bin/jorpelu/com/Tree.class
  2. +20
    -24
      src/jorpelu/com/Tree.java

BIN
bin/jorpelu/com/Tree.class View File


+ 20
- 24
src/jorpelu/com/Tree.java View File

@ -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("__"));
}
}
}
}

Loading…
Cancel
Save