Class FileSystemUtils



  • public class FileSystemUtils
    extends Object
    • Method Detail

      • mkdirs

        public static boolean mkdirs(File dir)
      • hasExtensions

        public static boolean hasExtensions(File root,
                                            String... extensions)
      • exists

        public static boolean exists(File... files)
        Returns true if at least one of the files exists.
      • exists

        public static boolean exists(Path... files)
        Returns true iff one of the files exists otherwise false
      • deleteRecursively

        public static boolean deleteRecursively(File[] roots,
                                                boolean deleteRoots)
        Deletes the given files recursively. if deleteRoots is set to true the given root files will be deleted as well. Otherwise only their content is deleted.
      • deleteRecursively

        public static boolean deleteRecursively(File... roots)
        Deletes the given files recursively including the given roots.
      • deleteRecursively

        public static boolean deleteRecursively(File root,
                                                boolean deleteRoot)
        Delete the supplied File - for directories, recursively delete any nested directories or files as well.
        Parameters:
        root - the root File to delete
        deleteRoot - whether or not to delete the root itself or just the content of the root.
        Returns:
        true if the File was deleted, otherwise false
      • isAccessibleDirectory

        public static boolean isAccessibleDirectory(File directory,
                                                    ESLogger logger)
        Check that a directory exists, is a directory and is readable by the current user
      • moveFilesWithoutOverwriting

        public static void moveFilesWithoutOverwriting(File source,
                                                       File destination,
                                                       String suffix)
                                                throws IOException
        This utility copy a full directory content (excluded) under a new directory but without overwriting existing files. When a file already exists in destination dir, the source file is copied under destination directory but with a suffix appended if set or source file is ignored if suffix is not set (null).
        Parameters:
        source - Source directory (for example /tmp/es/src)
        destination - Destination directory (destination directory /tmp/es/dst)
        suffix - When not null, files are copied with a suffix appended to the original name (eg: ".new") When null, files are ignored
        Throws:
        IOException
      • copyDirectoryRecursively

        public static void copyDirectoryRecursively(File source,
                                                    File destination)
                                             throws IOException
        Copy recursively a dir to a new location
        Parameters:
        source - source dir
        destination - destination dir
        Throws:
        IOException
      • move

        public static void move(Path source,
                                Path destination)
                         throws IOException
        Move or rename a file to a target file. This method supports moving a file from different filesystems (not supported by Files.move()).
        Parameters:
        source - source file
        destination - destination file
        Throws:
        IOException