Class PathOperations

java.lang.Object
com.helger.io.file.PathOperations

@ThreadSafe public final class PathOperations extends Object
Wraps file operations.
Author:
Philip Helger
  • Field Details

    • 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:
  • Method Details

    • isExceptionOnDeleteRoot

      public static boolean isExceptionOnDeleteRoot()
      Check if an exception should be thrown when trying to delete the root directory.
      Returns:
      true if an exception will be thrown on root deletion attempts, false otherwise.
    • setExceptionOnDeleteRoot

      public static void setExceptionOnDeleteRoot(boolean bExceptionOnDeleteRoot)
      Enable or disable the exception that is thrown when trying to delete the root directory.
      Parameters:
      bExceptionOnDeleteRoot - true to throw an exception on root deletion attempts, false to disable it.
    • createDir

      public static @NonNull 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 be null.
      Returns:
      A non-null error code.
    • createDirIfNotExisting

      public static @NonNull 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 be null.
      Returns:
      A non-null error code.
    • createDirRecursive

      public static @NonNull 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 be null.
      Returns:
      A non-null error code.
    • createDirRecursiveIfNotExisting

      public static @NonNull 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 be null.
      Returns:
      A non-null error code.
      See Also:
    • deleteDir

      public static @NonNull 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 be null.
      Returns:
      A non-null error code.
    • deleteDirIfExisting

      public static @NonNull 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 be null.
      Returns:
      A non-null error code.
      See Also:
    • deleteDirRecursive

      public static @NonNull FileIOError deleteDirRecursive(@NonNull Path aDir)
      Delete an existing directory including all child objects.
      Parameters:
      aDir - The directory to be deleted. May not be null.
      Returns:
      A non-null error code.
    • deleteDirRecursiveIfExisting

      public static @NonNull 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 be null.
      Returns:
      A non-null error code.
    • deleteFile

      public static @NonNull FileIOError deleteFile(@NonNull Path aFile)
      Delete an existing file.
      Parameters:
      aFile - The file to be deleted. May not be null.
      Returns:
      A non-null error code.
    • deleteFileIfExisting

      public static @NonNull FileIOError deleteFileIfExisting(@NonNull Path aFile)
      Delete a file if it is existing.
      Parameters:
      aFile - The file to be deleted. May not be null.
      Returns:
      A non-null error code.
    • renameFile

      public static @NonNull FileIOError renameFile(@NonNull Path aSourceFile, @NonNull Path aTargetFile)
      Rename a file.
      Parameters:
      aSourceFile - The original file name. May not be null.
      aTargetFile - The destination file name. May not be null.
      Returns:
      A non-null error code.
    • renameDir

      public static @NonNull FileIOError renameDir(@NonNull Path aSourceDir, @NonNull Path aTargetDir)
      Rename a directory.
      Parameters:
      aSourceDir - The original directory name. May not be null.
      aTargetDir - The destination directory name. May not be null.
      Returns:
      A non-null error code.
    • copyFile

      public static @NonNull 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 be null. Needs to be an existing file.
      aTargetFile - The destination files. May not be null and may not be an existing file.
      Returns:
      A non-null error 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 be null.
      aTargetDir - The destination directory where to be copied. This directory may not be existing. May not be null.
      Returns:
      A non-null error code.