|
@ -1,27 +1,37 @@ |
|
|
package jorpelu.com; |
|
|
package jorpelu.com; |
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
import java.io.File; |
|
|
import java.io.IOException; |
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.Scanner; |
|
|
|
|
|
|
|
|
public class Tree { |
|
|
public class Tree { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws IOException { |
|
|
public static void main(String[] args) throws IOException { |
|
|
printFile(new File("."), ""); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printFile(pideRuta(), ""); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static File pideRuta() { |
|
|
|
|
|
System.out.println("Introduzca una ruta a analizar: "); |
|
|
|
|
|
Scanner sc = new Scanner(System.in); |
|
|
|
|
|
File f = null; |
|
|
|
|
|
try { |
|
|
|
|
|
f = new File(sc.next()); |
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
e.setStackTrace(e.getStackTrace()); |
|
|
|
|
|
} |
|
|
|
|
|
sc.close(); |
|
|
|
|
|
return f; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public static void printFile(File f, String spaces) { |
|
|
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("__")); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println(spaces.concat("|____").concat(f.getName())); |
|
|
|
|
|
if (f.isDirectory() && f.canRead()) { |
|
|
|
|
|
for (File file : f.listFiles()) { |
|
|
|
|
|
|
|
|
|
|
|
printFile(file, spaces.concat(" ")); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |