I have written a programme that receives a file as first argument and prints out a tree, but I want it to go deeper than just checking for subdirectories or file that the input file/folder contains.
import java.io.File;
public class DN12 {
public static void main(String[] args)throws Exception {
File file = new File(args[0]);
String fPath = file.getPath();
System.out.println(fPath);
File[] paths = file.listFiles();
for(int i=0; i<paths.length; i++) {
String path2 = paths[i].getPath();
String[] path3 = path2.split("/");
System.out.println(" |___"+path3[path3.length-1]);
}
}
}
Example input:
/p2/sources
My output:
/p2/viri
|___sun.txt
|___tree
|___abc.txt
Expected output:
/p2/viri
|___sun.txt
|___tree
| |___.DS_Store
| |___dir1
| | |___dir11
| | | |___b.txt
| | |___a.txt
| |___src
| | |___predavanja11
| | | |___TestDrzava.java
| | | |___Dnevi.java
| | | |___Drzave.java
| | | |___Oseba.java
| | | |___Delitelji.java
| | | |___Drzava.java
| | | |___Meseci.java
| | | |___TestOseba.java
| |___dir2
| | |___dir21
| | |___dir22
| | | |___e.txt
| | |___d.txt
|___abc.txt