List of usage examples for java.io FileFilter accept
boolean accept(File pathname);
From source file:com.jalios.ejpt.sync.utils.IOUtil.java
private static void deepListFilesVisitor(File file, FileFilter filter, boolean checkDir, List<File> list) { if (file.isDirectory()) { if (checkDir && filter != null && !filter.accept(file)) { return; }/*from w w w . j a v a2 s .c om*/ File[] files = file.listFiles(); for (int i = 0; i < files.length; i++) { deepListFilesVisitor(files[i], filter, checkDir, list); } } else { if (filter == null || filter.accept(file)) { list.add(file); } } }
From source file:org.opoo.util.PathUtils.java
private static void listFilesInternal(List<File> list, File dir, FileFilter filter, boolean recursive) { String ss[] = dir.list();// w w w . j a va2 s.c o m if (ss == null) return; for (String s : ss) { File f = new File(dir, s); if (f.isFile()) { if (filter == null || filter.accept(f)) { list.add(f); } } if (recursive && f.isDirectory()) { listFilesInternal(list, f, filter, recursive); } } }
From source file:Main.java
private static void innerListFiles(File dir, Collection<File> accumulator, FileFilter filter) { String[] filenames = dir.list(); if (filenames != null) { for (int i = 0; i < filenames.length; i++) { File file = new File(dir, filenames[i]); if (file.isDirectory()) { innerListFiles(file, accumulator, filter); } else { if (filter != null && filter.accept(file)) { accumulator.add(file); }//from www. ja v a2 s. c o m } } } }
From source file:org.jboss.pvt.harness.utils.DirUtils.java
/** * list accepted files in rootDir and its sub-dirs * @param rootDir//from w w w .jav a2 s . co m * @param fileFilter * @return */ public static Collection<File> listFilesRecursively(File rootDir, final FileFilter fileFilter) { if (rootDir == null || !rootDir.exists() || rootDir.isFile()) { return Collections.emptyList(); } Collection<File> files = FileUtils.listFilesAndDirs(rootDir, new AbstractFileFilter() { @Override public boolean accept(File file) { return file.isFile() && fileFilter.accept(file); } }, TrueFileFilter.INSTANCE); // remove dirs for (Iterator<File> it = files.iterator(); it.hasNext();) { File file = it.next(); if (file.isDirectory()) { it.remove(); } } return files; }
From source file:org.sakaiproject.kernel.util.FileUtil.java
/** * @param f//from w w w . j a v a 2 s . c o m * @param list * @param ff */ private static void addFile(File f, List<File> list, FileFilter ff) { if (f.exists()) { if (f.isDirectory()) { for (File fn : f.listFiles(ff)) { if (fn.isDirectory()) { addFile(fn, list, ff); } else { list.add(fn); } } } else if (ff.accept(f)) { list.add(f); } } }
From source file:net.sqs2.util.FileUtil.java
public static void deleteDirectory(File directory, FileFilter filter) { for (File file : directory.listFiles()) { if (filter.accept(file)) { if (file.isDirectory()) { deleteDirectory(file, filter); }/*www . j a va2 s . c om*/ file.delete(); } } if (filter.accept(directory)) { directory.delete(); } }
From source file:org.openflexo.toolbox.ZipUtils.java
public static void zipDir(int pathPrefixSize, File dirToZip, ZipOutputStream zos, IProgress progress, FileFilter filter) throws IOException { String[] dirList = dirToZip.list(); for (int i = 0; i < dirList.length; i++) { File f = new File(dirToZip, dirList[i]); if (filter == null || f != null && filter.accept(f)) { if (f.isDirectory()) { zipDir(pathPrefixSize, f, zos, progress, filter); } else { zipFile(pathPrefixSize, f, zos, progress); }/*w w w . jav a2 s .c o m*/ } } }
From source file:org.deegree.coverage.tools.RasterCommandUtils.java
private static List<File> getFiles(File root, boolean recurse, FileFilter fileFilter) { List<File> result = new LinkedList<File>(); if (root.isDirectory()) { for (File file : root.listFiles()) { if (file.isDirectory() && recurse) { result.addAll(getFiles(file, recurse, fileFilter)); } else if (file.isFile() && fileFilter.accept(file)) { result.add(file);/*from www. j av a 2 s.c om*/ } } } else { result.add(root); } return result; }
From source file:org.jahia.utils.FileUtils.java
/** * Moves the content of the directory to the specified one considering the filter. * @param srcDir the source directory to move content from * @param destDir the target directory/* ww w . j ava 2 s . c om*/ * @param filter a filter for inclusions * @throws IOException in case of an I/O errors */ public static void moveDirectoryContentToDirectory(File srcDir, File destDir, FileFilter filter) throws IOException { File[] files = srcDir.listFiles(); if (files != null && files.length > 0) { for (File f : files) { if (filter == null || filter.accept(f)) { org.apache.commons.io.FileUtils.moveToDirectory(f, destDir, true); } } } }
From source file:org.apache.ode.utils.fs.FileUtils.java
/** * Recursively collect all Files in the given directory and all its * subdirectories, applying the given FileFilter. The FileFilter is also applied to the given rootDirectory. * As a result the rootDirectory might be in the returned list. * <p>//from w w w. java 2 s .com * Returned files are ordered lexicographically but for each directory, files come before its sudirectories. * For instance:<br/> * test<br/> * test/alpha.txt<br/> * test/zulu.txt<br/> * test/a<br/> * test/a/alpha.txt<br/> * test/z<br/> * test/z/zulu.txt<br/> * <p> * instead of:<br/> * test<br/> * test/a<br/> * test/a/alpha.txt<br/> * test/alpha.txt<br/> * test/z<br/> * test/z/zulu.txt<br/> * test/zulu.txt<br/> * * @param rootDirectory * the top level directory used for the search * @param filter * a FileFilter used for accepting/rejecting individual entries * @return a List of found Files */ public static List<File> directoryEntriesInPath(File rootDirectory, FileFilter filter) { if (rootDirectory == null) { throw new IllegalArgumentException("File must not be null!"); } if (!rootDirectory.exists()) { throw new IllegalArgumentException("File does not exist!"); } ArrayList<File> collectedFiles = new ArrayList<File>(32); if (rootDirectory.isFile()) { if ((filter == null) || ((filter != null) && (filter.accept(rootDirectory)))) { collectedFiles.add(rootDirectory); } return collectedFiles; } FileUtils.directoryEntriesInPath(collectedFiles, rootDirectory, filter); return collectedFiles; }