2
I have this code here in JAVA where I need lists of folders and subfolders in tree format, but I can’t get it. Any help?
package Control;
import java.awt.Desktop;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
public class PercorreDir {
public static StringBuffer buffer = new StringBuffer();
public static int nespaço = 1;
public static String espaço = "";
public static StringBuffer percorre(File caminho){
if(caminho.isDirectory()){
buffer.append(espaço + caminho.getName()+"\n");
for (File subpasta: caminho.listFiles()) {
for (int cta = 0; cta < nespaço; cta++){
espaço += " ";
}
nespaço += 1;
percorre(subpasta);
}
} else {
nespaço = 0;
espaço = " ";
}
return buffer;
}
}
Your problem is in space, right? By the code above they must be "out of control"... (if it is something else, please clarify, I am writing an answer addressing this)
– mgibsonbr
Yes, it’s the spaces. I’ll edit and put a picture of how the output comes out
– Vinícius Novelli
No need, I can imagine... :)
– mgibsonbr