Java Utililty Methods File Find

List of utility methods to do File Find

Description

The list of methods to do File Find are organized into topic(s).

Method

Listfind(File absolutePath, FileFilter filter)
find files which has specified suffix.
List<File> sourceFileList = new LinkedList<File>();
return addFoundFileToList(sourceFileList, absolutePath, filter);
Filefind(File baseFile, String regex)
Find the file whose name matches the given regular expression.
if (baseFile.getAbsolutePath().matches(regex)) {
    return baseFile;
if (baseFile.exists() && baseFile.isDirectory()) {
    for (File child : listFiles(baseFile)) {
        File foundFile = find(child, regex);
        if (foundFile != null) {
            return foundFile;
...
Filefind(File dir, String baseName)
Find a file starting with the baseName .
if (dir == null)
    throw new IllegalArgumentException("directory can not be null");
if (baseName == null)
    throw new IllegalArgumentException("baseName can not be null");
File found = null;
File[] files = dir.listFiles();
if (files != null) {
    for (File file : files) {
...
Listfind(File dir, String suffix, Set ignore)
find
List<File> lst = new ArrayList<File>();
for (String fn : dir.list()) {
    if (ignore.contains(fn)) {
        continue;
    File f = new File(dir, fn);
    if (f.isFile() && fn.endsWith(suffix)) {
        lst.add(f);
...
Listfind(File file)
find
return find(file, null);
voidfind(File file, Pattern pattern, int limit, List found, Set visited)
find
if (visited.contains(file))
    throw new IOException("Circular file structure detected");
visited.add(file);
if (limit > -1 && found.size() >= limit)
    return;
if (file.isDirectory()) {
    File[] subFiles = file.listFiles();
    Arrays.sort(subFiles);
...
Filefind(File folder, final String name)
Find the File with the given name in the given folder, or its subfolders.
if (name != null && name.length() > 0 && folder != null && folder.isDirectory()) {
    File[] files = folder.listFiles(new FileFilter() {
        @Override
        public boolean accept(File file) {
            return (file.isDirectory() || file.getName().equals(name));
    });
    for (File file : files) {
...
ArrayListfind(File path, Boolean recursive)
Return all files beneath path.
ArrayList<File> files = new ArrayList<File>();
find(files, path, recursive);
return files;
Listfind(File root)
find
if (!root.isDirectory())
    throw new IllegalAccessError(root + " must be a folder.");
List<File> klazzes = new ArrayList<File>();
addFiles(klazzes, root);
return klazzes;
Filefind(final File fileDir, final String fileNameRegex)
Find a file in a given directory with the specified regex pattern.
File[] found = fileDir.listFiles(new FilenameFilter() {
    @Override
    public boolean accept(File dir, String name) {
        return name.matches(fileNameRegex);
});
if (found != null && found.length != 0) {
    if (found.length == 1) {
...