public final class Directory extends Object implements Serializable
java.io.File. Provides utility methods for working
with the directory represented by the path.
A Directory be constructed with a path that
represents an existing directory, or a path that represents no
existing file. The physical directory can be created later using
create().
| Modifier and Type | Class and Description |
|---|---|
static class |
Directory.DirectoryException
An exception type used to report
Directory related
problems. |
| Constructor and Description |
|---|
Directory()
Constructor that builds a Directory for the current working directory.
|
Directory(File directory)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
copyTo(Directory target,
boolean incremental)
Copy contents of the directory to the target directory.
|
void |
create()
Create the directory if it doesn't exist.
|
void |
delete()
Delete the directory.
|
void |
deleteContents()
Delete the contents of the directory.
|
boolean |
equals(Object o)
Delegate equality to our
File. |
File |
getFile()
Get as a
File. |
File |
getFile(File child)
Return a
File representing the absolute path of a file in this
directory. |
static FileFilter |
getMatchAllFilesFilter()
Returns a filter matching all files.
|
String[] |
getWarnings()
Return a list of warnings that have occurred since the last time
getWarnings() was called. |
int |
hashCode()
Delegate equality to our
File. |
boolean |
isParentOf(File file)
Test whether a File represents the name of a file that is a descendant of
the directory.
|
File[] |
listContents(FileFilter filter)
Equivalent to
listContents(filter, false, false). |
File[] |
listContents(FileFilter filter,
boolean includeDirectories,
boolean absolutePaths)
List the files in the hierarchy below the directory that have been modified
after
since. |
File |
rebaseFromCWD(File file)
If possible, convert a path relative to the current working directory to
a path relative to this directory.
|
List<File> |
rebasePath(String path)
Rebase a whole path by calling
#rebaseFile on each of its
elements and joining the result. |
File |
relativeFile(File file,
boolean mustBeChild)
Convert the supplied
file, to a path relative to this directory. |
public Directory()
public Directory(File directory) throws Directory.DirectoryException
directory - The directory path upon which this
Directory operates.Directory.DirectoryException - If the path directory
represents a file that exists but is not a directory.public static FileFilter getMatchAllFilesFilter()
public void create()
throws Directory.DirectoryException
Directory.DirectoryException - If the directory could not be created.public File getFile(File child)
File representing the absolute path of a file in this
directory.child - Relative file in this directory. If null, the
result is equivalent to getFile().File.public File[] listContents(FileFilter filter)
listContents(filter, false, false).filter - Filter that controls the files that are returned.listContents(FileFilter, boolean, boolean)public File[] listContents(FileFilter filter, boolean includeDirectories, boolean absolutePaths)
since.filter - Filter that controls the files that are returned.includeDirectories - Whether to include directories in the returned files. Only
directories that match the filter will be returned.absolutePaths - Whether returned files should be relative to the directory or
absolute.public void deleteContents()
throws Directory.DirectoryException
Does nothing if the directory does not exist.
Directory.DirectoryException - If a file could not be deleted. The
contents of the directory are left in an indeterminate state.delete()public void delete()
throws Directory.DirectoryException
Directory.DirectoryException - If the directory could not be deleted.deleteContents()public File rebaseFromCWD(File file)
file - The input path. Relative to the CWD, or absolute.public File relativeFile(File file, boolean mustBeChild)
file, to a path relative to this directory.
The file need not exist.
If file is relative, this directory is considered its base.
file - The file to search for.mustBeChild - If true and path belongs to another file system;
is absolute with a different base path; or is a relative path
outside of the directory (../somewhere/else), then
null will be returned.null.public List<File> rebasePath(String path)
#rebaseFile on each of its
elements and joining the result.path - The path.public boolean isParentOf(File file)
file - File to test.boolean => file is a descendant.public void copyTo(Directory target, boolean incremental) throws IOException
target - Target directory.incremental - true => copy newer files to the
directory. false => overwrite the target directory.IOException - If a file could not be copied. The contents
of the target directory are left in an indeterminate state.public String[] getWarnings()
getWarnings() was called.public int hashCode()
File.Copyright © 2000-2014. All Rights Reserved.