Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. import java.io.File;
  2. import java.util.Arrays;
  3.  
  4.  
  5. public class Tree {
  6.     public static void main(String[] args) {
  7.         new App();
  8.     }
  9.  
  10. }
  11.  
  12. class App{
  13.     private File a;
  14.     private String path;
  15.     App(){
  16.         path = "/home/asi2/carpeta";
  17.         a = new File(path);
  18.         doTree(0);
  19.     }
  20.     private void doTree(int depth) {
  21.         File list[];
  22.         StringBuilder sep = new StringBuilder();
  23.         //Drawing the tree..
  24.         for(int i = 0; i < depth; i++){
  25.             if(i < depth - 1){
  26.                 sep.append("|   ");
  27.             }
  28.             else{
  29.                 sep.append("|-->");
  30.             }
  31.         }
  32.         if(a.isDirectory()){
  33.             System.out.println( sep.toString() + "(D)" + a.getName() );
  34.             list = a.listFiles();
  35.             Arrays.sort(list); //This will sort file objects in alphabetical order.
  36.             for( int i = 0; i < list.length; i++ ){
  37.                 a = list[i];
  38.                 doTree(depth + 1); //Going deeper ohh yeah! xD
  39.             }
  40.            
  41.         }
  42.         else{
  43.             System.out.println( sep.toString() + "(A)" + a.getName() );
  44.             //just a file, nothing more to do
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement