rendered paste bodyimport java.io.*;import java.util.*;public class JWalker { private int j = -1; private int numOfFiles = 0; private int numOfDirs = 0; private int numOfReadErrors = 0; private int lastRank = 0; private String dirOcurancePattern = ""; private final void draw(String fileName, int rank, boolean isLastInDir) { int i; if(new File(fileName).isDirectory() && rank != lastRank); if(isLastInDir) dirOcurancePattern+="D"; else dirOcurancePattern+="d"; for (i=0; i < rank; i++) { if(dirOcurancePattern.charAt(i)=='D') System.out.print(" "); else System.out.print("| "); } System.out.print(isLastInDir ? "`-- " + fileName + "\n" : "|-- " + fileName + "\n"); lastRank = i; } final void reset() { numOfFiles = 0; numOfDirs = 0; numOfReadErrors = 0; dirOcurancePattern = null; j = -1; } final void showPattern() { System.out.println(dirOcurancePattern); } final void printStats() { System.out.println("\ndirectories: " + numOfDirs + ", files: " + numOfFiles + ", read errors: " + numOfReadErrors); } private final void scan(String path) { File dir = new File(path); File[] dirContents = dir.listFiles(); Arrays.sort(dirContents); j++; for (File x : dirContents) { if (x.canRead()) { draw(x.getName(), j, x == dirContents[dirContents.length - 1]); if (x.isDirectory()) { numOfDirs++; scan(x.getAbsolutePath()); } else numOfFiles++; } else { numOfReadErrors++; draw(x.getName() + " [error reading]", j, x == dirContents[dirContents.length - 1]); } dirOcurancePattern = dirOcurancePattern.substring(0, dirOcurancePattern.length() - 1); } j--; } public static void main(String[] args) { JWalker jw = new JWalker(); if(args.length==0) { jw.scan("."); jw.printStats(); } else { for(int i=0;i<args.length;i++) { jw.scan(args[i]); jw.printStats(); jw.reset(); } } }}