I have a method in my source for work with directory paths and files names. Some paths and file names occasionally are written with '´' or 'ñ' chars.
Problem is that directory path with that specials chars is not recognized as directory and is recognized as file. I occasionally need to read the file extension and when file has that chars the code don't works and don't reach de extension.
public static void listarDirectorio(File f, String separador) {
File[] ficheros = f.listFiles();
File ficheroTratado = null;
logM.escribeLog(separador + "Ruta listada: " + f.getName(), false);
for (int x = 0; x < ficheros.length; x++) {
ficheroTratado = null;
ficheroTratado = ficheros[x];
if (!ficheros[x].isDirectory()) {
if (esBorrable(ficheroTratado.getName())) {
// logM.escribeLog(
// "Fichero borrado: " + ficheroTratado.getName(),
// true);
}
}
if (ficheros[x].isDirectory()
&& !ficheros[x].getName().startsWith("@")) {
String nuevo_separador;
nuevo_separador = separador + " # ";
listarDirectorio(ficheros[x], nuevo_separador);
}
}
}
public static boolean esBorrable(String nFichero) {
boolean esBorrable = false;
try {
String extension = "";
int extIndex = nFichero.lastIndexOf(".");
String ruta = "";
//logM.escribeLog("nombre de fichero: " + nFichero, false);
extension = nFichero.substring(extIndex, extIndex + 4);
//logM.escribeLog("extension que tengo: " + extension, false);
for (int i = 0; i < instance.getArrayExtensiones().size(); i++) {
ruta = "";
ruta = instance.getArrayExtensiones().get(i);
if (ruta.equalsIgnoreCase(extension)) {
//( logM.escribeLog("Este es borrable", false);
esBorrable = true;
} else {
esBorrable = false;
}
}
} catch (Exception e) {
logM.escribeLog("Problema al tratar el fichero: " + nFichero, false);
e.printStackTrace();
return false;
}
return esBorrable;
}
I hope you can help me with that issue.