Class FileFolderManager


  • public class FileFolderManager
    extends Object
    • Method Detail

      • getAllSubFolder

        public static Collection<File> getAllSubFolder​(String path)
        Gets all the folders (an only the folders, not the files) that are directly inside the specified directory. Throws an UtilException if the specified path doesn't denote a directory or if the listing of all of its directories fails.
        Parameters:
        path - the path of the directory.
        Returns:
        a collection of folders.
      • getAllFile

        public static Collection<File> getAllFile​(String path)
        Returns all the files (and only the files, not the directories) that are directly inside the given directory. Throws an UtilException if the specified path doesn't denote a directory or if the listing of all of its files fails.
        Parameters:
        path - the path of the directory
        Returns:
        a collection of files
      • getAllImages

        public static Collection<File> getAllImages​(String path)
        Returns all the images that are inside the given directory and its subdirectories. Throws an UtilException if the specified path doesn't denote a directory or if the recursive listing of all the images fails.
        Parameters:
        path - the path of the directory.
        Returns:
        a collection of image files.
      • getAllWebPages

        public static Collection<File> getAllWebPages​(String path)
        Gets all the web pages that are inside the specified directory and its subdirectories, whatever their type (HTML, ...). Throws an UtilException if the specified path doesn't denote a directory or if the recursive listing of all the web pages fails.
        Parameters:
        path - the path of the directory containing web pages.
        Returns:
        a collection of web pages.
      • getAllHTMLWebPages

        public static Collection<File> getAllHTMLWebPages​(String path)
        Gets all the HTML web pages that are inside the specified directory and its subdirectories. Throws an UtilException if the specified path doesn't denote a directory or if the recursive listing of all the HTML web pages fails.
        Parameters:
        path - the path of the directory containing web pages.
        Returns:
        a collection of HTML pages.
      • createFolder

        public static void createFolder​(String path)
        Creates the specified folder. If the specified path doesn't denote a directory, does nothing. Throws an UtilException if the folder creation fails.
        Parameters:
        path - the path of the folder to create.
      • createFolder

        public static void createFolder​(File directory)
        Creates the specified folder. Throws an UtilException if the folder creation fails.
        Parameters:
        directory - the folder.
      • moveFolder

        public static void moveFolder​(String path,
                                      String newPath)
        Moves or rename the specified folder to the new one. If the path and the new path denote the same parent directory, then it means the folder will be renamed to the name ending the specified newPath. Otherwise, the folder located by the given path will be moved to the new path and will be renamed accordingly the name ending the newPath parameter. Throws an UtilException if the specified path doesn't denote a directory or if the folder moving/renaming fails.
        Parameters:
        path - the path of the folder to rename or to move.
        newPath - the new path of the folder.
      • deleteFolder

        public static void deleteFolder​(String path)
        Deletes the specified directory recursively and quietly.
        Parameters:
        path - the path of a directory
      • createFile

        public static void createFile​(String directoryPath,
                                      String fileName,
                                      String fileContent)
        Creates the specified file into the given directory with the specified content. Throws an UtilException if the specified path doesn't denote a directory or if file creation fails.
        Parameters:
        directoryPath - the path of the directory into which the file will be created.
        fileName - the name of the file to create.
        fileContent - the content of the file. The content is expected to be encoded in UTF-8.
      • renameFile

        public static void renameFile​(String directoryPath,
                                      String name,
                                      String newName)
        Renames the specified file in the given directory with the new specified name. Throws an UtilException if the specified path doesn't denote a directory or if the file in this directory isn't a file or if the renaming fails.
        Parameters:
        directoryPath - the path of the directory containing the file to rename.
        name - the name of the file.
        newName - the new name of the file.
      • deleteFile

        public static void deleteFile​(String path)
        Deletes the specified file. Throws an UtilException if the deletion fails.
        Parameters:
        path - the path of the file to delete.
      • getFileContent

        public static Optional<String> getFileContent​(String directoryPath,
                                                      String fileName)
        Gets the content of the specified file. Throws an UtilException if the specified path doesn't denote a directory or if the reading of the file content fails.
        Parameters:
        directoryPath - the path of the directory containing the file to read.
        fileName - the name of the file.
        Returns:
        the content of the whole file as a String instance. The content is expected to be encoded in UTF-8.