Browse Source

Project Finished

main
Jesus 2 years ago
commit
8cbc2e628d
7 changed files with 113 additions and 0 deletions
  1. +10
    -0
      .classpath
  2. +17
    -0
      .project
  3. +2
    -0
      .settings/org.eclipse.core.resources.prefs
  4. +14
    -0
      .settings/org.eclipse.jdt.core.prefs
  5. BIN
      bin/com/jesuspinar/main/Main$1.class
  6. BIN
      bin/com/jesuspinar/main/Main.class
  7. +70
    -0
      src/com/jesuspinar/main/Main.java

+ 10
- 0
.classpath View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

+ 17
- 0
.project View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>tree-cmd-java</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

+ 2
- 0
.settings/org.eclipse.core.resources.prefs View File

@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8

+ 14
- 0
.settings/org.eclipse.jdt.core.prefs View File

@ -0,0 +1,14 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=17

BIN
bin/com/jesuspinar/main/Main$1.class View File


BIN
bin/com/jesuspinar/main/Main.class View File


+ 70
- 0
src/com/jesuspinar/main/Main.java View File

@ -0,0 +1,70 @@
package com.jesuspinar.main;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) {
File folder = new File(".");
StringBuilder sb = renderFolder(folder);
System.out.println(sb.toString());
}
private static StringBuilder renderFolder(File folder) {
return renderFolder(folder, 0, new StringBuilder(), false, new ArrayList<>());
}
private static StringBuilder renderFolder(File folder, int level, StringBuilder sb,
boolean isLast, List<Boolean> hierarchyTree) {
indent(sb, level, isLast, hierarchyTree).append(folder.getName()).append("\n");
File[] objects = folder.listFiles((FilenameFilter) new FilenameFilter() {
@Override
public boolean accept(File current, String name) {
return new File(current, name).isDirectory();
}
});
for (int i = 0; i < objects.length; i++) {
boolean last = ((i + 1) == objects.length);
// esto significa que la carpeta actual todavía tendrá que imprimir sub
//carpetas a este nivel, entonces necesitamos continuar imprimiendo |
hierarchyTree.add(i != objects.length - 1);
renderFolder(objects[i], level + 1, sb, last, hierarchyTree);
// hace saltar el último valor al volver de un nivel inferior a un nivel superior
hierarchyTree.remove(hierarchyTree.size() - 1);
}
return sb;
}
private static StringBuilder indent(StringBuilder sb, int level,
boolean isLast, List<Boolean> hierarchyTree) {
String indentContent = "\u2502 ";
for (int i = 0; i < hierarchyTree.size() - 1; ++i) {
// determina si necesitamos imprimir | en este nivel para mostrar la estructura del árbol
// es decir, si esta carpeta tiene una carpeta hermana que se va a imprimir más tarde
if (hierarchyTree.get(i)) {
sb.append(indentContent);
} else {
sb.append(" ");
}
}
if (level > 0) {
sb.append(isLast
? "\u2514\u2500\u2500"
: "\u251c\u2500\u2500").append(" ");
}
return sb;
}
}

Loading…
Cancel
Save