Package com.pnfsoftware.jeb.util.io
Class DirectoryEnumerator
java.lang.Object
com.pnfsoftware.jeb.util.io.DirectoryEnumerator
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
s passing
the File.isFile()
test.-
Constructor Summary
ConstructorsConstructorDescriptionDirectoryEnumerator
(File base) Create a new directory enumerator.DirectoryEnumerator
(File base, String filterString, boolean recurse) Create a new directory enumerator. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addBlackListedDirectory
(String dirname) Record a simple directory name (not path) that should not be recursively explored.boolean
iterator()
list()
Browse the folder(s) and retrieve the matching files.void
void
setFilterString
(String filterString, boolean matchCaseInsensitive, boolean matchUnicode) void
setRecurse
(boolean recurse) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
DirectoryEnumerator
Create a new directory enumerator.- Parameters:
base
- base folderfilterString
- optional widlcard filter string for filenamesrecurse
- true to recursively enumerate sub-directories.- Throws:
IllegalArgumentException
- on initialization error
-
DirectoryEnumerator
Create a new directory enumerator. The enumerator is filter-less (it matches on all files) and does not recurse over sub-directories.- Parameters:
base
-
-
-
Method Details
-
setFilterString
public void setFilterString(String filterString, boolean matchCaseInsensitive, boolean matchUnicode) - Parameters:
filterString
- non-null filter string; to disable filters, usesetFilter(Pattern)
matchCaseInsensitive
-matchUnicode
-
-
setFilter
- Parameters:
pattern
- optional regex pattern, null to disable
-
getFilter
- Returns:
-
setRecurse
public void setRecurse(boolean recurse) - Parameters:
recurse
-
-
isRecurse
public boolean isRecurse()- Returns:
-
addBlackListedDirectory
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.- Parameters:
dirname
-
-
getBlacklistedDirnames
- Returns:
-
list
Browse the folder(s) and retrieve the matching files.- Returns:
- a list of files
-
iterator
-