1

I use this code to read all .csv files into directory:

        File directoryPath = new File("C:\\in_progress");
        FilenameFilter textFileFilter = (dir, name) -> {
            String lowercaseName = name.toLowerCase();
            if (lowercaseName.endsWith(".csv")) {
                return true;
            } else {
                return false;
            }
        };
        // List of all the csv files
        File filesList[] = directoryPath.listFiles(textFileFilter);
        System.out.println("List of the text files in the specified directory:");
        for(File file : filesList) {
            System.out.println("File name: "+file.getName());
            System.out.println("File path: "+file.getAbsolutePath());
            System.out.println("Size :"+file.getTotalSpace());
            System.out.println(" ");
        }

I want also to list all files which are located in many sub directories into the main directory. How this can be implemented?

Peter Penzov
  • 1,126
  • 134
  • 430
  • 808
  • Does this answer your question? [List all files from a directory recursively with Java](https://stackoverflow.com/questions/2534632/list-all-files-from-a-directory-recursively-with-java) – Turing85 Nov 12 '22 at 16:19
  • Can you show me how I need to modify my code in order to implement the functionality? – Peter Penzov Nov 12 '22 at 16:21
  • What part is unclear? – Turing85 Nov 12 '22 at 16:22
  • I want to implement this functionality with less memory usage maybe with Stream if possible because I have hundreds of files for read. – Peter Penzov Nov 12 '22 at 16:24
  • Doesn't sound like a big issue to me. Have you verified that there *is* actually a performance-/memory-problem with the solutions provided in the post I linked? – Turing85 Nov 12 '22 at 16:26
  • @PeterPenzov The answers linked in Turing85's first comment contain an example that uses [java.nio.file.DirectoryStream](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/nio/file/DirectoryStream.html). I do not know if that is more memory-efficient (I somehow doubt it), but it is a "streaming" approach. – Thomas Behr Nov 12 '22 at 16:31

0 Answers0