Package com.helger.io.file
Class PathOperations
java.lang.Object
com.helger.io.file.PathOperations
Wraps file operations.
- Author:
- Philip Helger
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanThe default value for warning if we're about to delete the root directory. -
Method Summary
Modifier and TypeMethodDescriptionstatic @NonNull FileIOErrorcopyDirRecursive(@NonNull Path aSourceDir, @NonNull Path aTargetDir) Copy a directory including all child objects.static @NonNull FileIOErrorCopies the source file to the target file.static @NonNull FileIOErrorCreate a new directory.static @NonNull FileIOErrorcreateDirIfNotExisting(@NonNull Path aDir) Create a new directory if it does not exist.static @NonNull FileIOErrorcreateDirRecursive(@NonNull Path aDir) Create a new directory.static @NonNull FileIOErrorcreateDirRecursiveIfNotExisting(@NonNull Path aDir) Create a new directory if it does not exist.static @NonNull FileIOErrorDelete an existing directory.static @NonNull FileIOErrordeleteDirIfExisting(@NonNull Path aDir) Delete an existing directory if it is existing.static @NonNull FileIOErrordeleteDirRecursive(@NonNull Path aDir) Delete an existing directory including all child objects.static @NonNull FileIOErrordeleteDirRecursiveIfExisting(@NonNull Path aDir) Delete an existing directory including all child objects if it is existing.static @NonNull FileIOErrordeleteFile(@NonNull Path aFile) Delete an existing file.static @NonNull FileIOErrordeleteFileIfExisting(@NonNull Path aFile) Delete a file if it is existing.static booleanCheck if an exception should be thrown when trying to delete the root directory.static @NonNull FileIOErrorRename a directory.static @NonNull FileIOErrorrenameFile(@NonNull Path aSourceFile, @NonNull Path aTargetFile) Rename a file.static voidsetExceptionOnDeleteRoot(boolean bExceptionOnDeleteRoot) Enable or disable the exception that is thrown when trying to delete the root directory.
-
Field Details
-
DEFAULT_EXCEPTION_ON_DELETE_ROOT
public static final boolean DEFAULT_EXCEPTION_ON_DELETE_ROOTThe default value for warning if we're about to delete the root directory.- See Also:
-
-
Method Details
-
isExceptionOnDeleteRoot
public static boolean isExceptionOnDeleteRoot()Check if an exception should be thrown when trying to delete the root directory.- Returns:
trueif an exception will be thrown on root deletion attempts,falseotherwise.
-
setExceptionOnDeleteRoot
public static void setExceptionOnDeleteRoot(boolean bExceptionOnDeleteRoot) Enable or disable the exception that is thrown when trying to delete the root directory.- Parameters:
bExceptionOnDeleteRoot-trueto throw an exception on root deletion attempts,falseto disable it.
-
createDir
Create a new directory. The direct parent directory already needs to exist.- Parameters:
aDir- The directory to be created. May not benull.- Returns:
- A non-
nullerror code.
-
createDirIfNotExisting
Create a new directory if it does not exist. The direct parent directory already needs to exist.- Parameters:
aDir- The directory to be created if it does not exist. May not benull.- Returns:
- A non-
nullerror code.
-
createDirRecursive
Create a new directory. The parent directories are created if they are missing.- Parameters:
aDir- The directory to be created. May not benull.- Returns:
- A non-
nullerror code.
-
createDirRecursiveIfNotExisting
Create a new directory if it does not exist. The direct parent directory already needs to exist.- Parameters:
aDir- The directory to be created if it does not exist. May not benull.- Returns:
- A non-
nullerror code. - See Also:
-
deleteDir
Delete an existing directory. The directory needs to be empty before it can be deleted.- Parameters:
aDir- The directory to be deleted. May not benull.- Returns:
- A non-
nullerror code.
-
deleteDirIfExisting
Delete an existing directory if it is existing. The directory needs to be empty before it can be deleted.- Parameters:
aDir- The directory to be deleted. May not benull.- Returns:
- A non-
nullerror code. - See Also:
-
deleteDirRecursive
Delete an existing directory including all child objects.- Parameters:
aDir- The directory to be deleted. May not benull.- Returns:
- A non-
nullerror code.
-
deleteDirRecursiveIfExisting
Delete an existing directory including all child objects if it is existing.- Parameters:
aDir- The directory to be deleted. May not benull.- Returns:
- A non-
nullerror code.
-
deleteFile
Delete an existing file.- Parameters:
aFile- The file to be deleted. May not benull.- Returns:
- A non-
nullerror code.
-
deleteFileIfExisting
Delete a file if it is existing.- Parameters:
aFile- The file to be deleted. May not benull.- Returns:
- A non-
nullerror code.
-
renameFile
Rename a file.- Parameters:
aSourceFile- The original file name. May not benull.aTargetFile- The destination file name. May not benull.- Returns:
- A non-
nullerror code.
-
renameDir
Rename a directory.- Parameters:
aSourceDir- The original directory name. May not benull.aTargetDir- The destination directory name. May not benull.- Returns:
- A non-
nullerror code.
-
copyFile
Copies the source file to the target file.- Parameters:
aSourceFile- The source file to use. May not benull. Needs to be an existing file.aTargetFile- The destination files. May not benulland may not be an existing file.- Returns:
- A non-
nullerror code.
-
copyDirRecursive
public static @NonNull FileIOError copyDirRecursive(@NonNull Path aSourceDir, @NonNull Path aTargetDir) Copy a directory including all child objects.- Parameters:
aSourceDir- The source directory to be copied. May not benull.aTargetDir- The destination directory where to be copied. This directory may not be existing. May not benull.- Returns:
- A non-
nullerror code.
-