public class

DirectoryEnumerator

extends Object
implements Iterable<T>
java.lang.Object
   ↳ com.pnfsoftware.jeb.util.io.DirectoryEnumerator

Class Overview

List (full in-memory enumeration) or iterate over a directory contents, with support for recursion and regex file filters. The returned File Objects are real File Files passing the File.isFile() test.

Summary

Public Constructors
DirectoryEnumerator(File base, String filterString, boolean recurse)
Create a new directory enumerator.
DirectoryEnumerator(File base)
Create a new directory enumerator.
Public Methods
void addBlackListedDirectory(String dirname)
Record a simple directory name (not path) that should not be recursively explored.
Collection<String> getBlacklistedDirnames()
Pattern getFilter()
boolean isRecurse()
Iterator<File> iterator()
List<File> list()
Browse the folder(s) and retrieve the matching files.
void setFilter(Pattern pattern)
void setFilterString(String filterString, boolean matchCaseInsensitive, boolean matchUnicode)
void setRecurse(boolean recurse)
[Expand]
Inherited Methods
From class java.lang.Object
From interface java.lang.Iterable

Public Constructors

public DirectoryEnumerator (File base, String filterString, boolean recurse)

Create a new directory enumerator.

Parameters
base base folder
filterString optional widlcard filter string for filenames
recurse true to recursively enumerate sub-directories.
Throws
IllegalArgumentException on initialization error

public DirectoryEnumerator (File base)

Create a new directory enumerator. The enumerator is filter-less (it matches on all files) and does not recurse over sub-directories.

Public Methods

public void addBlackListedDirectory (String dirname)

Record a simple directory name (not path) that should not be recursively explored. Ignored if the enumerator is not recursive. The base directory is always explored, even if its simple name is blacklisted.

Example: 'xyz' is blacklisted, the search is recursive and starts in '/xyz':
- "/xyz/..." is explored, no matter what
- if it exists, "/xyz/xyz/..." and its sub-dirs WONT be explored
- if it exists, "/xyz/0/1/xyz/..." and its sub-dirs WONT be explored
- if it exists, file named '/xyz/xyz' or /xyz/foo/xyz" WILL be returned.

public Collection<String> getBlacklistedDirnames ()

public Pattern getFilter ()

public boolean isRecurse ()

public Iterator<File> iterator ()

public List<File> list ()

Browse the folder(s) and retrieve the matching files.

Returns
  • a list of files

public void setFilter (Pattern pattern)

Parameters
pattern optional regex pattern, null to disable

public void setFilterString (String filterString, boolean matchCaseInsensitive, boolean matchUnicode)

Parameters
filterString non-null filter string; to disable filters, use setFilter(Pattern)

public void setRecurse (boolean recurse)