Browse Source

Añado los colores

master
vigliom 2 years ago
parent
commit
426f4c4299
3 changed files with 33 additions and 5 deletions
  1. +1
    -1
      README.md
  2. BIN
      bin/jorpelu/com/Tree.class
  3. +32
    -4
      src/jorpelu/com/Tree.java

+ 1
- 1
README.md View File

@ -2,7 +2,7 @@
###### Jorge Pérez Ludeña
Aplicación que imita el comando tree.
Pide una ruta, la cual analiza
Hago que pinte por colores las diferentes carpetas
Asi sale la consola
~~~


BIN
bin/jorpelu/com/Tree.class View File


+ 32
- 4
src/jorpelu/com/Tree.java View File

@ -1,17 +1,36 @@
package jorpelu.com;
import java.io.File;
import java.io.IOException;
import java.io.File;
import java.util.Scanner;
public class Tree {
static int contador = 0;
static String colores[] = new String[7];
public static final String ANSI_GREEN = "\u001B[32m";
public static final String ANSI_RESET = "\u001B[0m"; /*
* public static final String ANSI_BLACK = "\u001B[30m"; public static final
* String ANSI_RED = "\u001B[31m";
*
* 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 void main(String[] args) throws IOException {
colores[0] = "\u001B[30m";
colores[1] = "\u001B[31m";
colores[2] = "\u001B[32m";
colores[3] = "\u001B[33m";
colores[4] = "\u001B[34m";
colores[5] = "\u001B[35m";
colores[6] = "\u001B[36m";
printFile(pideRuta(), "");
}
public static File pideRuta() {
System.out.println("Introduzca una ruta a analizar: ");
System.out.println(ANSI_GREEN.concat("Introduzca una ruta a analizar: "+ANSI_RESET));
Scanner sc = new Scanner(System.in);
File f = null;
try {
@ -25,13 +44,22 @@ public class Tree {
}
public static void printFile(File f, String spaces) {
System.out.println(spaces.concat("|____").concat(f.getName()));
System.out.println(spaces.concat("|____").concat(f.getName())+ANSI_RESET);
if (f.isDirectory() && f.canRead()) {
for (File file : f.listFiles()) {
printFile(file, spaces.concat(" "));
printFile(file, spaces.concat(" " + colores[contador]));
}
}
if(contador<6) {
contador++;
}else{
contador = 0;
}
}
}

Loading…
Cancel
Save