Today I'm ready through the code below the files that are in the directory passed by the parameter, however now I would like to also list the files that are in the subdirectories. I did some searches but I did not find anything that did not change my structure a lot, I also thought that removing isFile()
would solve, but it did not work.
void indexaArquivosDoDiretorio(File raiz) {
FilenameFilter filtro = new FilenameFilter() {
public boolean accept(File arquivo, String nome) {
return nome.toLowerCase().endsWith(".pdf")
|| nome.toLowerCase().endsWith(".odt")
|| nome.toLowerCase().endsWith(".doc")
|| nome.toLowerCase().endsWith(".docx")
|| nome.toLowerCase().endsWith(".ppt")
|| nome.toLowerCase().endsWith(".pptx")
|| nome.toLowerCase().endsWith(".xls")
|| nome.toLowerCase().endsWith(".txt")
|| nome.toLowerCase().endsWith(".rtf");
}
};
for (File arquivo : raiz.listFiles(filtro)) {
if (arquivo.isFile()) {
try {
// Extrai o conteúdo do arquivo com o Tika;
String textoExtraido = getTika().parseToString(arquivo);
indexaArquivo(arquivo, textoExtraido);
System.out.println(arquivo);
i++;
} catch (Exception e) {
logger.error(e);
}
} else {
indexaArquivosDoDiretorio(arquivo);
}
}
}