|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.evanmclean.evlib.io.Folders
public final class Folders
Perform certain folder/directory related operations. Also see Files
.
Method Summary | |
---|---|
static boolean |
clean(File path,
boolean including_empty_files)
Recursively clears a folder of any empty folders and optionally, zero-length files as well. |
static void |
clear(File folder)
Clear the contents of a folder. |
static void |
copy(File from,
File to)
Will recursively copy a folder to the target path. |
static File |
createTempFolder(String prefix,
String suffix)
Creates an new folder in the default temporary-file folder, using the given prefix and suffix to generate its name. |
static File |
createTempFolder(String prefix,
String suffix,
File parent)
Creates a new folder in the specified parent folder, using the given prefix and suffix strings to generate its name. |
static void |
del(File path)
Delete the folder (if it exists) and all its contents. |
static boolean |
del(File path,
boolean quietly)
Delete the folder (if it exists) and all its contents. |
static boolean |
delQuietly(File path)
Delete the folder (if it exists) and all its contents. |
static void |
forceMksClear(File folder)
If the folder already exists, clear its contents, otherwise create it and all necessary parent folders - if the specified path is a file, delete it first then create the folder with the same name. |
static boolean |
isAllEmpty(File path)
Checks if the path has any non-zero length files, or is just folders and empty files (or doesn't even exist). |
static boolean |
isEmpty(File path)
Checks the path specified is a zero length file, an empty folder or does not exist. |
static boolean |
isNotAllEmpty(File path)
Checks if the path has any non-zero length files, or is just folders and empty files (or doesn't even exist). |
static boolean |
isNotEmpty(File path)
Checks the path specified is a zero length file, an empty folder or does not exist. |
static boolean |
isNotOnlyFolders(File path)
Checks if the path contains any files at all, or just zero or more folders and sub-folders. |
static boolean |
isOnlyFolders(File path)
Checks if the path contains any files at all, or just zero or more folders and sub-folders. |
static void |
mk(File folder)
Create the folder if it does not already exist. |
static void |
mks(File folder)
Create the folder and all necessary parent folders if they do not already exist. |
static void |
mksClear(File folder)
If the folder already exists, clear its contents, otherwise create it and all necessary parent folders. |
static void |
move(File from,
File to)
Will try and rename a folder, and failing that will copy then delete. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static boolean clean(File path, boolean including_empty_files) throws IOException
path
- The path to clear.including_empty_files
- Remove zero-length files as well as empty folders.
IOException
public static void clear(File folder) throws IOException
folder
- The folder to delete.
IOException
- If unable to fully delete the contents of the folder or the folder
doesn't exist.public static void copy(File from, File to) throws IOException
from
- Where to copy from.to
- Where to copy to. This folder should either not exist or be an empty
folder.
IOException
- If there was an error.public static File createTempFolder(String prefix, String suffix) throws IOException
createTempFolder(prefix, suffix, null)
.
prefix
- The prefix string to be used in generating the folder's name; must
be at least three characters long.suffix
- The suffix string to be used in generating the folder's name; may be
null
, in which case the suffix ".tmp"
will
be used.
IllegalArgumentException
- If the prefix
argument contains fewer than three
characters.
IOException
- If a folder could not be created.public static File createTempFolder(String prefix, String suffix, File parent) throws IOException
Creates a new folder in the specified parent folder, using the given prefix and suffix strings to generate its name. If this method returns successfully then it is guaranteed that:
Note: Folders are not automatically deleted on exit or anything. It is up to the application to cleanup as necessary.
The prefix
argument must be at least three characters long. It
is recommended that the prefix be a short, meaningful string such as
"hjb"
or "mail"
. The suffix
argument
may be null
, in which case the suffix ".tmp"
will
be used.
The name of the new folder will be generated by concatenating the prefix, some internally-generated characters, and the suffix.
If the parent
argument is null
then the
system-dependent default temporary-file folder will be used. The default
temporary-file folder is specified by the system property
java.io.tmpdir
. On UNIX systems the default value of this
property is typically "/tmp"
or "/var/tmp"
; on
Microsoft Windows systems it is typically "C:\\WINNT\\TEMP"
. A
different value may be given to this system property when the Java virtual
machine is invoked, but programmatic changes to this property are not
guaranteed to have any effect upon the temporary folder used by this
method.
prefix
- The prefix string to be used in generating the folder's name; must
be at least three characters long.suffix
- The suffix string to be used in generating the folder's name; may be
null
, in which case the suffix ".tmp"
will
be used.parent
- The parent folder in which the folder is to be created, or
null
if the default temporary-file folder is to be
used.
IOException
- If a file could not be created.
IllegalArgumentException
- If the prefix
argument contains fewer than three
characterspublic static void del(File path) throws IOException
Files.del(File)
. Note, if
given a file, it will just delete the file, equivalent behaviour to
Files.del(File)
in this case.
path
- The folder to delete.
IOException
- If unable to fully delete the folder.public static boolean del(File path, boolean quietly) throws IOException
Files.del(File)
. Note, if
given a file, it will just delete the file, equivalent behaviour to
Files.del(File)
in this case.
path
- The folder to delete.quietly
- Only throw the IO exception if quietly
is
false
.
quietly
is true
.
IOException
- If unable to fully delete the folder and quietly
is
false
.public static boolean delQuietly(File path)
path
- The folder to delete.
public static void forceMksClear(File folder) throws IOException
folder
- Folder to create or clear.
IOException
- If it could create or delete whatever it needed to.public static boolean isAllEmpty(File path)
path
-
public static boolean isEmpty(File path) throws IOException
path
- The path the check.
IOException
- If folder
does not represent a file or a folder.public static boolean isNotAllEmpty(File path)
path
-
public static boolean isNotEmpty(File path) throws IOException
path
- The path the check.
IOException
- If folder
does not represent a file or a folder.public static boolean isNotOnlyFolders(File path)
path
-
public static boolean isOnlyFolders(File path)
path
-
public static void mk(File folder) throws IOException
File.mkdir()
but throws an exception on error instead of
returning false
.
folder
- Folder to create.
IOException
- If it could not create the folder, or the path already exists and
is not a folder.public static void mks(File folder) throws IOException
File.mkdirs()
but throws an
exception on error instead of returning false
.
folder
- Folder to create.
IOException
- If it could not create the folder, or the path already exists and
is not a folder.public static void mksClear(File folder) throws IOException
folder
- Folder to create or clear.
IOException
- If it could create or delete whatever it needed to, or the path
already exists and is not a folder.public static void move(File from, File to) throws IOException
from
- Folder to copy.to
- Where to copy to. This path must not already exist.
IOException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |