net.hblok.io
Class FileFilterUtils

java.lang.Object
  extended by net.hblok.io.FileFilterUtils

public class FileFilterUtils
extends Object

Convenience methods for retrieving list of file from a single directory, or recursively in a directory hierarchy.

Author:
Havard Rast Blok

Method Summary
static List<File> listDirectories(File directory, boolean recursive)
          List all sub directories of the specified directory.
static List<File> listfiles(File directory, FileFilter filter, boolean recursive)
          List all files and sub directories of the specified directory, according to the specified filter.
static List<File> listfiles(File directory, FilenameFilter filter, boolean recursive)
          List all files and sub directories of the specified directory, according to the specified filter.
static List<File> listfilesRecursive(File directory)
          List all files and sub directories of the specified directory recursively.
static void printFiles(File directory, FileFilter filter, boolean recursive)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

listfiles

public static List<File> listfiles(File directory,
                                   FileFilter filter,
                                   boolean recursive)
List all files and sub directories of the specified directory, according to the specified filter. If the recursive flag is true, these sub directories are also searched recursively.

Parameters:
directory - the base directory to start listing in
filter - the FileFilter which is applied to each file and directory during the retrial
recursive - if true, iterate all sub directories as well
Returns:
a list of all the files and directories found, or and empty list if directory did not exists, or there was an IO error.

listfiles

public static List<File> listfiles(File directory,
                                   FilenameFilter filter,
                                   boolean recursive)
List all files and sub directories of the specified directory, according to the specified filter. If the recursive flag is true, these sub directories are also searched recursively.

Parameters:
directory - the base directory to start listing in
filter - the FilenameFilter which is applied to each file and directory during the retrial
recursive - if true, iterate all sub directories as well
Returns:
a list of all the files and directories found.

listfilesRecursive

public static List<File> listfilesRecursive(File directory)
List all files and sub directories of the specified directory recursively.

Parameters:
directory - the base directory to start listing in
Returns:
a list of all the files and directories found.

listDirectories

public static List<File> listDirectories(File directory,
                                         boolean recursive)
List all sub directories of the specified directory. If the recursive flag is true, these sub directories are also searched recursively.

Parameters:
directory - the base directory to start listing in
recursive - if true, iterate all sub directories as well
Returns:
a list of all directories found.

printFiles

public static void printFiles(File directory,
                              FileFilter filter,
                              boolean recursive)