public static List<File> getFiles(Language lang, FileMatcher fm, Configuration configuration) { File downloadPath = new File(configuration.get().getString("download.path")); if (downloadPath == null) { throw new IllegalArgumentException("missing configuration for download.path"); } if (LOG != null) LOG.debug("scanning download path " + downloadPath + " for files"); List<File> matchingFiles = new ArrayList<File>(); File langDir = new File(downloadPath, lang.getLangCode()); if (!langDir.isDirectory()) { return matchingFiles; } String mostRecent = null; for (File dateDir : langDir.listFiles((FileFilter) DirectoryFileFilter.INSTANCE)) { if (!dateDir.isDirectory()) { continue; } // skip if older than most recent if (mostRecent != null && dateDir.getName().compareTo(mostRecent) < 0) { continue; } List<File> lf = fm.matchFiles(Arrays.asList(dateDir.listFiles())); if (!lf.isEmpty()) { mostRecent = dateDir.getName(); matchingFiles = lf; } } return matchingFiles; }