static List < Path > getFilesMatching ( Path directory , String syntaxAndPattern , String excludesExt ) throws IOException { PathMatcher matcher = directory . getFileSystem ( ) . getPathMatcher ( syntaxAndPattern ) ; List < Path > parts = Files . walk ( directory ) . filter ( matcher :: matches ) . filter ( path -> excludesExt == null || ! path . toString ( ) . endsWith ( excludesExt ) ) . collect ( Collectors . toList ( ) ) ; Collections . sort ( parts ) ; return parts ; }
Returns all the files in a directory that match the given pattern and that don t have the given extension .