Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.util.Arrays;
- public class Tree {
- public static void main(String[] args) {
- new App();
- }
- }
- class App{
- private File a;
- private String path;
- App(){
- path = "/home/asi2/carpeta";
- a = new File(path);
- doTree(0);
- }
- private void doTree(int depth) {
- File list[];
- StringBuilder sep = new StringBuilder();
- //Drawing the tree..
- for(int i = 0; i < depth; i++){
- if(i < depth - 1){
- sep.append("| ");
- }
- else{
- sep.append("|-->");
- }
- }
- if(a.isDirectory()){
- System.out.println( sep.toString() + "(D)" + a.getName() );
- list = a.listFiles();
- Arrays.sort(list); //This will sort file objects in alphabetical order.
- for( int i = 0; i < list.length; i++ ){
- a = list[i];
- doTree(depth + 1); //Going deeper ohh yeah! xD
- }
- }
- else{
- System.out.println( sep.toString() + "(A)" + a.getName() );
- //just a file, nothing more to do
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement