public class FileWalker
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
PATTERN_SEPARATOR
The character to be used to separate filename patterns (';') as String.
|
static char |
PATTERN_SEPARATOR_CHAR
The character to be used to separate filename patterns (';').
|
static java.lang.String |
RECURSIVE_DIR_WILDCARD
The wildcard pattern that indicates a recursive walk-through in a
single string definition (i.e.
|
Constructor and Description |
---|
FileWalker(FileHandler handler)
Initialize the new instance with a file handler.
|
FileWalker(FileHandler handler,
char digitWildcard)
Initialize the new instance with a file handler and a wildcard character
for digits.
|
FileWalker(IFileProcessor processor)
Initialize the new instance with a file processor.
|
Modifier and Type | Method and Description |
---|---|
static FileWalker |
create(FileHandler handler)
Creates a new instance with a file handler.
|
static FileWalker |
create(IFileProcessor processor)
Creates a new instance with a file processor.
|
protected ExtendedFileFilter |
createFileFilter() |
protected boolean |
directoryEnd(java.io.File dir) |
protected boolean |
directoryStart(java.io.File dir,
int count) |
protected java.lang.Character |
getDigitWildcard() |
protected char |
getDigitWildcardChar() |
protected FileHandler |
getFileHandler() |
protected IFileProcessor |
getFileProcessor() |
protected boolean |
getGoOn() |
boolean |
getHandleContentBeforeDirectory()
Returns whether or not the contents of a directory should be walked through
before the directory is passed to the file processor.
|
static long |
handleAll(java.lang.String startDir,
FileHandler handler)
Creates a new instance and handles with the given file handler all files
under the given start directory and its sub-directories.
|
protected boolean |
handleFile(java.io.File file) |
protected boolean |
hasDigitWildcard() |
static long |
processAll(java.lang.String startDir,
IFileProcessor processor)
Creates a new instance and processes with the given file processor all files
under the given start directory and its sub-directories.
|
protected boolean |
restrictedWilcardMatch()
Returns true to define that '*' wildcards don't match empty strings.
|
protected long |
scanDirectories(java.io.File startDir,
java.io.FilenameFilter filter,
boolean recursive,
boolean subDirsFirst) |
protected void |
setDigitWildcard(java.lang.Character newValue) |
FileWalker |
setDigitWildcardChar(char digitWildcard)
Sets the given character as a wildcard character to match
digits ('0'-'9') only.
|
protected void |
setFileHandler(FileHandler newValue) |
protected void |
setFileProcessor(IFileProcessor newValue) |
protected void |
setGoOn(boolean newValue) |
FileWalker |
setHandleContentBeforeDirectory(boolean newValue)
Defines whether or not the contents of a directory should be walked through
before the directory is passed to the file handler.
|
long |
walkThrough(java.lang.String searchPattern)
Walks through all directories specified by the given pattern and calls
the file handler or file processor for each file that matches the file part
in the given pattern.
|
long |
walkThrough(java.lang.String dir,
java.io.FilenameFilter filter,
boolean recursive)
Walks through the given directory and optionally through all its
sub-directories as well.
|
long |
walkThrough(java.lang.String dir,
java.lang.String pattern,
boolean recursive)
This method starts in the given directory to search for all files
matching the given pattern(s).
|
long |
walkThroughAllRecursive(java.lang.String dir)
Walks through the given directory and all its sub-directories as well.
|
long |
walkThroughDirectories(java.lang.String startDir,
java.io.FilenameFilter filter,
boolean recursive)
Walks through the given start directory and optionally through all its
sub-directories as well.
|
long |
walkThroughDirectoriesSubDirsFirst(java.lang.String startDir,
java.io.FilenameFilter filter)
Walks through the given start directory and recursively through all its sub-directories.
|
public static final char PATTERN_SEPARATOR_CHAR
public static final java.lang.String PATTERN_SEPARATOR
public static final java.lang.String RECURSIVE_DIR_WILDCARD
public FileWalker(IFileProcessor processor)
public FileWalker(FileHandler handler)
public FileWalker(FileHandler handler, char digitWildcard)
handler
- The file handler that gets all found filesdigitWildcard
- A character that is used as wildcard for digits in filname patternspublic static FileWalker create(IFileProcessor processor)
public static FileWalker create(FileHandler handler)
public static long processAll(java.lang.String startDir, IFileProcessor processor)
public static long handleAll(java.lang.String startDir, FileHandler handler)
public long walkThrough(java.lang.String dir, java.lang.String pattern, boolean recursive)
If recursive is true it goes down to each subdirectory and doing
the same there.
For each matching file (non-directory) the defined FileHandler.handle()
is called.
dir
- The directory where to startpattern
- The file name pattern(s) for filtering out the correct files ( wildcards '*' and '?' )recursive
- If set to true, the file selection is going down to all subdirectoriespublic long walkThrough(java.lang.String searchPattern)
Examples:
"prog/lib\/**\/a*.jar" ==> Starts in directory prog\lib and walks
recursive through all sub-directories to pass all files that match pattern
"a*.jar" to the file handler.
"d:/temp/tmp???.doc" ==> Passes all files that match pattern
"tmp???.doc" to the file handler.
searchPattern
- The pattern that specifies the path and files to walk throughpublic long walkThroughAllRecursive(java.lang.String dir)
dir
- The directory to start from.public long walkThrough(java.lang.String dir, java.io.FilenameFilter filter, boolean recursive)
dir
- The directory to start from.filter
- The filter that decides whether or not a file is passed to the FileHandler.recursive
- If true all sub-directories are scanned as well.public long walkThroughDirectories(java.lang.String startDir, java.io.FilenameFilter filter, boolean recursive)
startDir
- The directory to start from.filter
- The filter that decides whether or not a directory is passed to the FileHandler.recursive
- If true all sub-directories are scanned as well.walkThroughDirectoriesSubDirsFirst(String, FilenameFilter)
public long walkThroughDirectoriesSubDirsFirst(java.lang.String startDir, java.io.FilenameFilter filter)
FileDeleteProcessor
.
However, it scans all directories, even those that do not match the filter.startDir
- The directory to start from.filter
- The filter that decides whether or not a directory is passed to the FileHandler.walkThroughDirectories(String, FilenameFilter, boolean)
public FileWalker setDigitWildcardChar(char digitWildcard)
digitWildcard
- The placeholder character for digitspublic boolean getHandleContentBeforeDirectory()
public FileWalker setHandleContentBeforeDirectory(boolean newValue)
protected long scanDirectories(java.io.File startDir, java.io.FilenameFilter filter, boolean recursive, boolean subDirsFirst)
protected char getDigitWildcardChar()
protected boolean hasDigitWildcard()
protected ExtendedFileFilter createFileFilter()
protected boolean restrictedWilcardMatch()
protected boolean handleFile(java.io.File file)
protected boolean directoryEnd(java.io.File dir)
protected boolean directoryStart(java.io.File dir, int count)
protected FileHandler getFileHandler()
protected void setFileHandler(FileHandler newValue)
protected IFileProcessor getFileProcessor()
protected void setFileProcessor(IFileProcessor newValue)
protected boolean getGoOn()
protected void setGoOn(boolean newValue)
protected java.lang.Character getDigitWildcard()
protected void setDigitWildcard(java.lang.Character newValue)