2
Today I list through the code below the files that are in the directory passed by the parameter, but now I would like to list also the files that are in the subdirectories. I did some searches but I did not find anything that does not alter my structure much, also found that removing the isFile() I would, but it didn’t 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);
        }
    }
}
						
Now that I answered that I read the restriction
com listFiles(). Should it be like this or does my answer answer? If it’s not a restriction, and it’s just a suggestion, could I change the title?– Math
@Math I wanted with the listFiles() because I think it gets leaner. But thanks anyway for the contribution, I’ll take a look if it’s to learn.
– Matt S
No problem, I went in the excitement because I already knew this walkTreeFile(), rs.. If I have a little time I’ll look into this method you spoke of.
– Math