Search code examples
pattern-matchingfilestreamfilepath

Java How to list files with directory with pattern matcher


The file structure is like the following:

root
 -- [anything]
   -- access.log
 -- [anything]
   -- access.log

path: /root/*/access.log

Thank you.


Solution

  •     DirectoryScanner scanner = new DirectoryScanner();
        scanner.setIncludes(new String[]{"*/access.log"});
        scanner.setBasedir(basePath);
        scanner.scan();
        String[] files = scanner.getIncludedFiles();
    

    This is the simplest solution using org.apache.tools.ant.DirectoryScanner