Package com.helger.commons.io.file
Class PathOperations
- java.lang.Object
-
- com.helger.commons.io.file.PathOperations
-
@ThreadSafe public final class PathOperations extends Object
Wraps file operations.- Author:
- Philip Helger
-
-
Field Summary
Fields Modifier and Type Field Description static booleanDEFAULT_EXCEPTION_ON_DELETE_ROOTThe default value for warning if we're about to delete the root directory.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static FileIOErrorcopyDirRecursive(Path aSourceDir, Path aTargetDir)Copy a directory including all child objects.static FileIOErrorcopyFile(Path aSourceFile, Path aTargetFile)Copies the source file to the target file.static FileIOErrorcreateDir(Path aDir)Create a new directory.static FileIOErrorcreateDirIfNotExisting(Path aDir)Create a new directory if it does not exist.static FileIOErrorcreateDirRecursive(Path aDir)Create a new directory.static FileIOErrorcreateDirRecursiveIfNotExisting(Path aDir)Create a new directory if it does not exist.static FileIOErrordeleteDir(Path aDir)Delete an existing directory.static FileIOErrordeleteDirIfExisting(Path aDir)Delete an existing directory if it is existing.static FileIOErrordeleteDirRecursive(Path aDir)Delete an existing directory including all child objects.static FileIOErrordeleteDirRecursiveIfExisting(Path aDir)Delete an existing directory including all child objects if it is existing.static FileIOErrordeleteFile(Path aFile)Delete an existing file.static FileIOErrordeleteFileIfExisting(Path aFile)Delete a file if it is existing.static booleanisExceptionOnDeleteRoot()static FileIOErrorrenameDir(Path aSourceDir, Path aTargetDir)Rename a directory.static FileIOErrorrenameFile(Path aSourceFile, Path aTargetFile)Rename a file.static voidsetExceptionOnDeleteRoot(boolean bExceptionOnDeleteRoot)
-
-
-
Field Detail
-
DEFAULT_EXCEPTION_ON_DELETE_ROOT
public static final boolean DEFAULT_EXCEPTION_ON_DELETE_ROOT
The default value for warning if we're about to delete the root directory.- See Also:
- Constant Field Values
-
-
Method Detail
-
isExceptionOnDeleteRoot
public static boolean isExceptionOnDeleteRoot()
-
setExceptionOnDeleteRoot
public static void setExceptionOnDeleteRoot(boolean bExceptionOnDeleteRoot)
-
createDir
@Nonnull public static FileIOError createDir(@Nonnull Path aDir)
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
@Nonnull public static FileIOError createDirIfNotExisting(@Nonnull Path aDir)
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
@Nonnull public static FileIOError createDirRecursive(@Nonnull Path aDir)
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
@Nonnull public static FileIOError createDirRecursiveIfNotExisting(@Nonnull Path aDir)
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:
createDirRecursive(Path)
-
deleteDir
@Nonnull public static FileIOError deleteDir(@Nonnull Path aDir)
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
@Nonnull public static FileIOError deleteDirIfExisting(@Nonnull Path aDir)
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:
deleteDir(Path)
-
deleteDirRecursive
@Nonnull public static FileIOError deleteDirRecursive(@Nonnull Path aDir)
Delete an existing directory including all child objects.- Parameters:
aDir- The directory to be deleted. May not benull.- Returns:
- A non-
nullerror code.
-
deleteDirRecursiveIfExisting
@Nonnull public static FileIOError deleteDirRecursiveIfExisting(@Nonnull Path aDir)
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
@Nonnull public static FileIOError deleteFile(@Nonnull Path aFile)
Delete an existing file.- Parameters:
aFile- The file to be deleted. May not benull.- Returns:
- A non-
nullerror code.
-
deleteFileIfExisting
@Nonnull public static FileIOError deleteFileIfExisting(@Nonnull Path aFile)
Delete a file if it is existing.- Parameters:
aFile- The file to be deleted. May not benull.- Returns:
- A non-
nullerror code.
-
renameFile
@Nonnull public static FileIOError renameFile(@Nonnull Path aSourceFile, @Nonnull Path aTargetFile)
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
@Nonnull public static FileIOError renameDir(@Nonnull Path aSourceDir, @Nonnull Path aTargetDir)
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
@Nonnull public static FileIOError copyFile(@Nonnull Path aSourceFile, @Nonnull Path aTargetFile)
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
@Nonnull public static 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.
-
-