Added listing of files
This commit is contained in:
@@ -2,10 +2,6 @@
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk11"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
||||
1
.project
1
.project
@@ -12,7 +12,6 @@
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.scala-ide.sdt.core.scalanature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
|
||||
@@ -14,11 +14,12 @@ public class Directory {
|
||||
Long localSize;
|
||||
Long totalSize;
|
||||
List<Directory> children;
|
||||
File[] files = null;
|
||||
|
||||
public Directory(Directory parent, File fsdir) {
|
||||
this.parent = parent;
|
||||
this.fsdir = fsdir;
|
||||
File[] files = fsdir.listFiles(new FileFilter() {
|
||||
files = fsdir.listFiles(new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(File f) {
|
||||
return f.isFile() && !Files.isSymbolicLink(f.toPath());
|
||||
|
||||
@@ -5,6 +5,11 @@ import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class Test {
|
||||
//
|
||||
private static String CORNER = " └── ";
|
||||
private static String BLANK = " ";
|
||||
private static String JUNCTION = " ├── ";
|
||||
private static String LINE = " │ ";
|
||||
|
||||
static void recurse(Directory d, int level) {
|
||||
List<Directory> subs = d.children;
|
||||
@@ -12,22 +17,21 @@ public class Test {
|
||||
Directory child = subs.get(i);
|
||||
Long ts = child.totalSize;
|
||||
if (true) /* (ts >= 100000000L) */ {
|
||||
StringBuilder sb = new StringBuilder(String.format("%,16d ", ts));
|
||||
StringBuilder sb = new StringBuilder(String.format("D %,16d ", ts));
|
||||
String s = "";
|
||||
Directory temp = child;
|
||||
int loop = 0;
|
||||
while (temp.parent != null) {
|
||||
/* ─ │ ┌ ┐ └ ┘ ├ ┤ ┬ ┴ ┼ */
|
||||
if (temp.parent.children.indexOf(temp) == temp.parent.children.size() - 1) {
|
||||
if (loop == 0) {
|
||||
s = " └── " + s;
|
||||
s = CORNER + s;
|
||||
} else {
|
||||
s = " " + s;
|
||||
s = BLANK + s;
|
||||
}
|
||||
} else if (loop == 0) {
|
||||
s = " ├── " + s;
|
||||
s = JUNCTION + s;
|
||||
} else {
|
||||
s = " │ " + s;
|
||||
s = LINE + s;
|
||||
}
|
||||
temp = temp.parent;
|
||||
loop++;
|
||||
@@ -35,13 +39,47 @@ public class Test {
|
||||
sb.append(s).append(child.fsdir.getName());
|
||||
System.out.println(sb.toString());
|
||||
}
|
||||
if (level <= 4) recurse(child, level + 1);
|
||||
|
||||
/* if (level <= 4) */
|
||||
|
||||
recurse(child, level + 1);
|
||||
|
||||
int j = 0;
|
||||
for (File f : child.files) {
|
||||
Long fs = f.length();
|
||||
StringBuilder sb = new StringBuilder(String.format(" %,16d ", fs));
|
||||
String s = "";
|
||||
Directory temp = child;
|
||||
int loop = 0;
|
||||
while (temp.parent != null) {
|
||||
if (temp.parent.children.indexOf(temp) == temp.parent.children.size() - 1) {
|
||||
s = BLANK + s;
|
||||
} else if (loop == 0) {
|
||||
s = JUNCTION + s;
|
||||
} else {
|
||||
s = LINE + s;
|
||||
}
|
||||
temp = temp.parent;
|
||||
loop++;
|
||||
}
|
||||
if (j == child.files.length - 1) {
|
||||
s = s + CORNER;
|
||||
} else {
|
||||
s = s + JUNCTION;
|
||||
}
|
||||
sb.append(s).append(f.getName());
|
||||
System.out.println(sb.toString());
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
Directory d = new Directory(null, new File("/home/rob"));
|
||||
String s = String.format("%,16d", d.totalSize) + " " + d.fsdir.getCanonicalPath();
|
||||
String parm = args.length > 0 ? args[0] : ".";
|
||||
File dir = new File(parm);
|
||||
// System.out.println(dir.getCanonicalPath() + "\n");
|
||||
Directory d = new Directory(null, dir);
|
||||
String s = String.format("D %,16d", d.totalSize) + " " + d.fsdir.getCanonicalPath();
|
||||
System.out.println(s);
|
||||
recurse(d, 1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user