List<File> (@NotNull Pattern pattern, @NotNull File dir) { List<File> found = new ArrayList<>(); File[] files = dir.listFiles(); if (files != null) { for (File file : files) { if (pattern.matcher(file.getName()).matches()) { found.add(file); } if (file.isDirectory()) { found.addAll(findFilesOrDirsByMask(pattern, file)); } } } return found; }