Advertisement
Guest User

Untitled

a guest
Apr 5th, 2020
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1.  
  2. package recurs1;
  3.  
  4. import java.io.*;
  5. import java.util.*;
  6.  
  7. public class j4 {
  8.    
  9.     public static void list1(File dir, String lvl) {
  10.         if(dir.isDirectory())
  11.         {
  12.             File dirs[] = dir.listFiles((File current, String name) -> {
  13.                 return new File(current, name).isDirectory();
  14.             });      
  15.             System.out.printf("%s\n", dir.getName());
  16.             for (int j = 0; j < dirs.length; j++) if(dirs[j].isDirectory()){
  17.                 System.out.print(lvl);
  18.                 System.out.print("--");
  19.                 if(j == dirs.length-1)
  20.                     lvl = lvl.substring(0, lvl.length()-1) + ' ';
  21.                 list1(dirs[j], lvl+"   |");
  22.             }
  23.         }
  24.     }
  25.    
  26.     public static void list1(File dir) {
  27.         list1(dir, "   |");
  28.     }
  29.    
  30.     public static void main(String[] args) {
  31.         Scanner in = new Scanner(System.in);
  32.         String path = "src";    //здесь указывать путь к папке
  33.         File dir = new File(path);
  34.         if(!dir.exists())
  35.         {
  36.             System.out.println("there's no such path");
  37.             return;
  38.         }
  39.         list1(dir);
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement