Browse Source

:D

master
Ivan Morell 2 years ago
parent
commit
bcead83856
5 changed files with 73 additions and 81 deletions
  1. +33
    -32
      README.md
  2. BIN
      bin/Package/MiTree.class
  3. BIN
      bin/Package/Tree.class
  4. +0
    -49
      src/Package/MiTree.java
  5. +40
    -0
      src/Package/Tree.java

+ 33
- 32
README.md View File

@ -12,38 +12,39 @@ Mi Propio Tree
```
Ejecuta el programa para que funcione similar a como funcionaria "tree" en un terminal
.classpath
.git
branches
COMMIT_EDITMSG
config
HEAD
hooks
index
logs
HEAD
refs
heads
master
objects
pack
refs
heads
master
tags
.project
.settings
org.eclipse.core.resources.prefs
org.eclipse.jdt.core.prefs
bin
module-info.class
Package
MiTree.class
README.md
src
module-info.java
Package
MiTree.java
\.
\.classpath
\.git
\branches
\COMMIT_EDITMSG
\config
\HEAD
\hooks
\index
\logs
\HEAD
\refs
\heads
\master
\objects
\pack
\refs
\heads
\master
\tags
\.project
\.settings
\org.eclipse.core.resources.prefs
\org.eclipse.jdt.core.prefs
\bin
\module-info.class
\Package
\Tree.class
\README.md
\src
\module-info.java
\Package
\Tree.java
```


BIN
bin/Package/MiTree.class View File


BIN
bin/Package/Tree.class View File


+ 0
- 49
src/Package/MiTree.java View File

@ -1,49 +0,0 @@
package Package;
import java.io.File;
public class MiTree {
static int cont = 1;
public static void main(String args[]) {
String ruta=".";
if (args.length>=1) ruta = args[0];
File file = new File(ruta);
treeRecursividad(file);
}
private static void treeRecursividad(File file) {
if(!file.exists())
return;
for(File f : file.listFiles()) {
if(f.isDirectory()) {
cont++;
print(f);
treeRecursividad(f);
} else {
print(f);
}
}
}
private static void print(File f) {
String tab = " ";
if(cont != 1) {
for(int i = 1;i<cont;i++) {
String masTab = "| ";
tab.concat(masTab);
}
}
System.out.println(tab+f.getName());
}
}

+ 40
- 0
src/Package/Tree.java View File

@ -0,0 +1,40 @@
package Package;
import java.io.File;
import java.io.IOException;
public class Tree {
public static void printFile(File f, String spaces) {
System.out.println(spaces.concat(File.separator).concat(f.getName()));
if (f.isDirectory() && f.canRead()) {
for (File file : f.listFiles()) {
String ext = f.getName();
String [] partes = ext.split(".");
System.out.print(partes[0]);
/*if(partes[1].equals("txt")) {
System.out.printf(ANSI_YELLOW+spaces.concat(File.separator).concat(f.getName())+ANSI_RESET);
}*/
printFile(file, spaces.concat(" "));
}
}
}
public static void main(String[] args) throws IOException {
String ruta = "Documentos";
if(args.length==1) {
printFile(new File(args[0]),"");
} else
printFile(new File("."), "");
}
public static final String ANSI_BLACK = "\u001B[30m";
public static final String ANSI_RED = "\u001B[31m";
public static final String ANSI_GREEN = "\u001B[32m";
public static final String ANSI_YELLOW = "\u001B[33m";
public static final String ANSI_BLUE = "\u001B[34m";
public static final String ANSI_PURPLE = "\u001B[35m";
public static final String ANSI_CYAN = "\u001B[36m";
public static final String ANSI_WHITE = "\u001B[37m";
public static final String ANSI_RESET = "\u001B[0m";
}

Loading…
Cancel
Save