Module org.jcommon

Class FileUtil

    • Constructor Detail

      • FileUtil

        public FileUtil()
    • Method Detail

      • size

        public static long size​(File path)
        Return the file or directory size in byte
        Parameters:
        path - the file or directory to check
        Returns:
        the complete size in bytes of the file or directory.
      • deleteDirectory

        public static boolean deleteDirectory​(File path)
        Delete recursively a directory and its content. After cleaning all the contents, the directory itself is deleted.
        Parameters:
        path - path to the directory (or file) you want to delete
        Returns:
        true if the delete was successfull and false if the delete was unable to erase all the directory.
        See Also:
        cleanDirectory(File)
      • cleanDirectory

        public static boolean cleanDirectory​(File path)
        Delete recursively the content of a directory. Only the directory content is deleted, the directory itself is not deleted.
        Parameters:
        path - path to the directory (or file) you want to clean
        Returns:
        true if the delete was successfull and false if the delete was unable to erase all the directory
        See Also:
        deleteDirectory(File)
      • copy

        public static boolean copy​(File source,
                                   File destination)
        Simple copy of a source file to a destination file
        Parameters:
        source - the path of the source file
        destination - the path of the destination file
        Returns:
        true if the copy was successfull and false if not
      • copyDirectory

        public static boolean copyDirectory​(File source,
                                            File destination)
        Copying recursively a directory to another. If the destination directory does not exist, it is created.
        Parameters:
        source - the source directory (or file to copy)
        destination - the destination directory.
        Returns:
        true if the copy was successfull, false if the copy was unsuccessfull
      • list

        public static List<File> list​(File dir,
                                      FileFilter filter,
                                      boolean recurse)
        List a directory and select files that are selected by the given file filter
        Parameters:
        dir - the directory to list.
        filter - the file filter that accept or not listed files.
        recurse - is set to true if the listing process have to enter subdirectory, false otherwise.
        Returns:
        the files that are selected by the given file filter
      • listPathes

        public static List<String> listPathes​(File dir,
                                              FileFilter filter,
                                              boolean recurse)
        List a directory and select files that are selected by the given file filter
        Parameters:
        dir - the directory to list.
        filter - the file filter that accept or not listed files.
        recurse - is set to true if the listing process have to enter subdirectory, false otherwise.
        Returns:
        the pathes of the files that are selected by the given file filter
      • list

        public static List<File> list​(File source,
                                      String regex,
                                      boolean recurse)
        List recursively a directory and select files that match the given regular expression.
        Parameters:
        source - the directory to list.
        regex - the regular expression that the tested file path have to match.
        recurse - is set to true if the listing process have to enter subdirectory, false otherwise.
        Returns:
        the list of files contained within the given directory and from witch path are matched by te given regular expression.