Added listing of files
This commit is contained in:
18
.classpath
18
.classpath
@@ -1,11 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<classpath>
|
<classpath>
|
||||||
<classpathentry kind="src" path="src"/>
|
<classpathentry kind="src" path="src"/>
|
||||||
<classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
|
<classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk11"/>
|
||||||
<attributes>
|
<classpathentry kind="output" path="bin"/>
|
||||||
<attribute name="module" value="true"/>
|
</classpath>
|
||||||
</attributes>
|
|
||||||
</classpathentry>
|
|
||||||
<classpathentry kind="output" path="bin"/>
|
|
||||||
</classpath>
|
|
||||||
|
|||||||
1
.project
1
.project
@@ -12,7 +12,6 @@
|
|||||||
</buildCommand>
|
</buildCommand>
|
||||||
</buildSpec>
|
</buildSpec>
|
||||||
<natures>
|
<natures>
|
||||||
<nature>org.scala-ide.sdt.core.scalanature</nature>
|
|
||||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
</natures>
|
</natures>
|
||||||
</projectDescription>
|
</projectDescription>
|
||||||
|
|||||||
14
README.md
14
README.md
@@ -1,8 +1,8 @@
|
|||||||
# treesize
|
# treesize
|
||||||
|
|
||||||
Rudimentäre Quick-and-dirty-Implementation des tree-Kommandos (Linux), einmal in Java und einmal in Scala
|
Rudimentäre Quick-and-dirty-Implementation des tree-Kommandos (Linux), einmal in Java und einmal in Scala
|
||||||
|
|
||||||
* 16-Oct-2019 Erstellt und in svn-Repo hochgeladen
|
* 16-Oct-2019 Erstellt und in svn-Repo hochgeladen
|
||||||
* 02-Jun-2022 Mit git2svn in lokales git-Repo migriert und in selbstgehosteten Gitea-Server gepusht
|
* 02-Jun-2022 Mit git2svn in lokales git-Repo migriert und in selbstgehosteten Gitea-Server gepusht
|
||||||
___
|
___
|
||||||
RS 02-Jun-2022
|
RS 02-Jun-2022
|
||||||
@@ -14,11 +14,12 @@ public class Directory {
|
|||||||
Long localSize;
|
Long localSize;
|
||||||
Long totalSize;
|
Long totalSize;
|
||||||
List<Directory> children;
|
List<Directory> children;
|
||||||
|
File[] files = null;
|
||||||
|
|
||||||
public Directory(Directory parent, File fsdir) {
|
public Directory(Directory parent, File fsdir) {
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.fsdir = fsdir;
|
this.fsdir = fsdir;
|
||||||
File[] files = fsdir.listFiles(new FileFilter() {
|
files = fsdir.listFiles(new FileFilter() {
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(File f) {
|
public boolean accept(File f) {
|
||||||
return f.isFile() && !Files.isSymbolicLink(f.toPath());
|
return f.isFile() && !Files.isSymbolicLink(f.toPath());
|
||||||
|
|||||||
@@ -5,6 +5,11 @@ import java.io.IOException;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Test {
|
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) {
|
static void recurse(Directory d, int level) {
|
||||||
List<Directory> subs = d.children;
|
List<Directory> subs = d.children;
|
||||||
@@ -12,22 +17,21 @@ public class Test {
|
|||||||
Directory child = subs.get(i);
|
Directory child = subs.get(i);
|
||||||
Long ts = child.totalSize;
|
Long ts = child.totalSize;
|
||||||
if (true) /* (ts >= 100000000L) */ {
|
if (true) /* (ts >= 100000000L) */ {
|
||||||
StringBuilder sb = new StringBuilder(String.format("%,16d ", ts));
|
StringBuilder sb = new StringBuilder(String.format("D %,16d ", ts));
|
||||||
String s = "";
|
String s = "";
|
||||||
Directory temp = child;
|
Directory temp = child;
|
||||||
int loop = 0;
|
int loop = 0;
|
||||||
while (temp.parent != null) {
|
while (temp.parent != null) {
|
||||||
/* ─ │ ┌ ┐ └ ┘ ├ ┤ ┬ ┴ ┼ */
|
|
||||||
if (temp.parent.children.indexOf(temp) == temp.parent.children.size() - 1) {
|
if (temp.parent.children.indexOf(temp) == temp.parent.children.size() - 1) {
|
||||||
if (loop == 0) {
|
if (loop == 0) {
|
||||||
s = " └── " + s;
|
s = CORNER + s;
|
||||||
} else {
|
} else {
|
||||||
s = " " + s;
|
s = BLANK + s;
|
||||||
}
|
}
|
||||||
} else if (loop == 0) {
|
} else if (loop == 0) {
|
||||||
s = " ├── " + s;
|
s = JUNCTION + s;
|
||||||
} else {
|
} else {
|
||||||
s = " │ " + s;
|
s = LINE + s;
|
||||||
}
|
}
|
||||||
temp = temp.parent;
|
temp = temp.parent;
|
||||||
loop++;
|
loop++;
|
||||||
@@ -35,13 +39,47 @@ public class Test {
|
|||||||
sb.append(s).append(child.fsdir.getName());
|
sb.append(s).append(child.fsdir.getName());
|
||||||
System.out.println(sb.toString());
|
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 {
|
public static void main(String[] args) throws IOException {
|
||||||
Directory d = new Directory(null, new File("/home/rob"));
|
String parm = args.length > 0 ? args[0] : ".";
|
||||||
String s = String.format("%,16d", d.totalSize) + " " + d.fsdir.getCanonicalPath();
|
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);
|
System.out.println(s);
|
||||||
recurse(d, 1);
|
recurse(d, 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,23 @@
|
|||||||
package dev.rsems.treesize.s
|
package dev.rsems.treesize.s
|
||||||
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
import scala.collection.mutable.ListBuffer
|
import scala.collection.mutable.ListBuffer
|
||||||
|
|
||||||
class Directory(val fsdir: File, val parent: Directory = null, val sort: Boolean = false) {
|
class Directory(val fsdir: File, val parent: Directory = null, val sort: Boolean = false) {
|
||||||
private var localSize = 0L
|
private var localSize = 0L
|
||||||
var children = ListBuffer[Directory]()
|
var children = ListBuffer[Directory]()
|
||||||
private val files = fsdir.listFiles
|
private val files = fsdir.listFiles
|
||||||
if (files != null)
|
if (files != null)
|
||||||
localSize = files.filter(f => f.isFile() && !Files.isSymbolicLink(f.toPath)).map(f => f.length).sum
|
localSize = files.filter(f => f.isFile() && !Files.isSymbolicLink(f.toPath)).map(f => f.length).sum
|
||||||
var totalSize = localSize
|
var totalSize = localSize
|
||||||
private val dirs = fsdir.listFiles
|
private val dirs = fsdir.listFiles
|
||||||
if (dirs != null) {
|
if (dirs != null) {
|
||||||
totalSize += dirs.filter(f => f.isDirectory() && !Files.isSymbolicLink(f.toPath)).map(dir => {
|
totalSize += dirs.filter(f => f.isDirectory() && !Files.isSymbolicLink(f.toPath)).map(dir => {
|
||||||
val subdir = new Directory(dir, this, sort)
|
val subdir = new Directory(dir, this, sort)
|
||||||
children += subdir
|
children += subdir
|
||||||
subdir.totalSize
|
subdir.totalSize
|
||||||
}).sum
|
}).sum
|
||||||
if (sort) children = children.sortBy(-_.totalSize)
|
if (sort) children = children.sortBy(-_.totalSize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,48 +1,48 @@
|
|||||||
package dev.rsems.treesize.s
|
package dev.rsems.treesize.s
|
||||||
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
object Test extends App {
|
object Test extends App {
|
||||||
// ─ │ ┌ ┐ └ ┘ ├ ┤ ┬ ┴ ┼
|
// ─ │ ┌ ┐ └ ┘ ├ ┤ ┬ ┴ ┼
|
||||||
val LineUpAndRight = " \u2514\u2500\u2500 "; // " └── "
|
val LineUpAndRight = " \u2514\u2500\u2500 "; // " └── "
|
||||||
val LineBlank = " ";
|
val LineBlank = " ";
|
||||||
val LineVerticalAndRight = " \u251c\u2500\u2500 "; // " ├── "
|
val LineVerticalAndRight = " \u251c\u2500\u2500 "; // " ├── "
|
||||||
val LineVertical = " \u2502 "; // " │ "
|
val LineVertical = " \u2502 "; // " │ "
|
||||||
|
|
||||||
def recurse(d: Directory, level: Int) {
|
def recurse(d: Directory, level: Int) {
|
||||||
for (child <- d.children) {
|
for (child <- d.children) {
|
||||||
val ts = child.totalSize
|
val ts = child.totalSize
|
||||||
val sb = new StringBuilder("%,16d ".format(ts))
|
val sb = new StringBuilder("%,16d ".format(ts))
|
||||||
var s = ""
|
var s = ""
|
||||||
var temp = child
|
var temp = child
|
||||||
var loop = 0
|
var loop = 0
|
||||||
while (temp.parent != null) {
|
while (temp.parent != null) {
|
||||||
if (temp.parent.children.indexOf(temp) == temp.parent.children.size - 1) {
|
if (temp.parent.children.indexOf(temp) == temp.parent.children.size - 1) {
|
||||||
if (loop == 0) {
|
if (loop == 0) {
|
||||||
s = "└─ " + s
|
s = "└─ " + s
|
||||||
} else {
|
} else {
|
||||||
s = " " + s
|
s = " " + s
|
||||||
}
|
}
|
||||||
} else if (loop == 0) {
|
} else if (loop == 0) {
|
||||||
s = "├─ " + s
|
s = "├─ " + s
|
||||||
} else {
|
} else {
|
||||||
s = "│ " + s
|
s = "│ " + s
|
||||||
}
|
}
|
||||||
temp = temp.parent
|
temp = temp.parent
|
||||||
loop += 1
|
loop += 1
|
||||||
}
|
}
|
||||||
sb.append(s).append(child.fsdir.getName)
|
sb.append(s).append(child.fsdir.getName)
|
||||||
println(sb.toString)
|
println(sb.toString)
|
||||||
|
|
||||||
// if (level <= 4)
|
// if (level <= 4)
|
||||||
|
|
||||||
recurse(child, level + 1)
|
recurse(child, level + 1)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val dir = new Directory(new File("/home/rob"))
|
val dir = new Directory(new File("/home/rob"))
|
||||||
val s = "%,16d".format(dir.totalSize) + " " + dir.fsdir.getCanonicalPath
|
val s = "%,16d".format(dir.totalSize) + " " + dir.fsdir.getCanonicalPath
|
||||||
println(s)
|
println(s)
|
||||||
recurse(dir, 1)
|
recurse(dir, 1)
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user