/** * Sorts files by file name, using <b>natural</b> sort. */ public T sortByName() { addComparator(new FileNameComparator(true)); return (T) this; }
/** * Sorts files by file extension. */ public T sortByExtension() { addComparator(new FileExtensionComparator(true)); return (T) this; }
/** * Sorts files by last modified time descending. */ public T sortByTimeDesc() { addComparator(new FileLastModifiedTimeComparator(false)); return (T) this; }
/** * Specifies the search path. */ public T searchPath(URL... searchPath) { for (URL url : searchPath) { searchPath(url); } return (T) this; }
/** * Performs scanning. */ @SuppressWarnings("StatementWithEmptyBody") public void find() { while (nextFile() != null) { } }
/** * If entry name is {@link #acceptEntry(String) accepted} invokes {@link #onEntry(EntryData)} a callback}. */ protected void scanEntry(EntryData entryData) { if (!acceptEntry(entryData.getName())) { return; } try { onEntry(entryData); } catch (Exception ex) { throw new FindFileException("Scan entry error: " + entryData, ex); } }
/** * Specifies the search path. Throws an exception if URL is invalid. */ public T searchPath(URL searchPath) { File file = FileUtil.toFile(searchPath); if (file == null) { throw new FindFileException("URL error: " + searchPath); } addPath(file); return (T) this; }
/** * Puts folders before files. */ public T sortFoldersFirst() { addComparator(new FolderFirstComparator(true)); return (T) this; }
/** * Specifies single search path. */ public T searchPath(File searchPath) { addPath(searchPath); return (T) this; }
/** * Adds generic sorting. */ public T sortWith(Comparator<File> fileComparator) { addComparator(fileComparator); return (T) this; }
protected void scanPaths(File... paths) { for (File path : paths) { scanPath(path); } }
/** * Scans provided paths. */ public void scan(File... paths) { scanPaths(paths); }
/** * Scans provided classpath. */ public void scan(URL... urls) { scanUrls(urls); }
/** * Sorts files by file names descending, using <b>natural</b> sort. */ public T sortByNameDesc() { addComparator(new FileNameComparator(false)); return (T) this; }
/** * Sorts files by file extension descending. */ public T sortByExtensionDesc() { addComparator(new FileExtensionComparator(false)); return (T) this; }
/** * Sorts files by last modified time. */ public T sortByTime() { addComparator(new FileLastModifiedTimeComparator(true)); return (T) this; }
/** * Puts files before folders. */ public T sortFoldersLast() { addComparator(new FolderFirstComparator(false)); return (T) this; }
/** * Specifies a set of search paths. */ public T searchPath(File... searchPath) { for (File file : searchPath) { addPath(file); } return (T) this; }
protected void scanPaths(String... paths) { for (String path : paths) { scanPath(path); } }