public interface Renameable
Interface Renameable provides methods for renaming files and directories.
  • Method Details

    • appendSystemTimeToFilename

      default String appendSystemTimeToFilename(File fileToRename)
      Returns the filename from the given file with the system time appended
      Parameters:
      fileToRename - the file to rename
      Returns:
      the filename with the system time appended
    • appendSystemTimeToFilename

      default String appendSystemTimeToFilename(File fileToRename, Date add2Name)
      Returns the filename from the given file with the specified date appended
      Parameters:
      fileToRename - the file
      add2Name - the date to add
      Returns:
      the filename with the specified date appended
    • changeAllFilenameSuffix

      default List<File> changeAllFilenameSuffix(File file, String oldSuffix, String newSuffix, boolean delete) throws IOException, FileDoesNotExistException, FileIsADirectoryException
      Changes all filenames with the specified suffix
      Parameters:
      file - the directory in which to change filenames
      oldSuffix - the suffix to replace
      newSuffix - the new suffix
      delete - if true, deletes files with the same name after renaming
      Returns:
      a list of files that could not be deleted if delete is true
      Throws:
      IOException - if an I/O exception occurs
      FileDoesNotExistException - if the file does not exist
      FileIsADirectoryException - if the file is a directory
    • changeFilenameSuffix

      default boolean changeFilenameSuffix(File file, String newSuffix, boolean delete) throws IOException, FileDoesNotExistException, FileIsADirectoryException
      Changes the suffix of the given file
      Parameters:
      file - the file to change
      newSuffix - the new suffix
      delete - if true, deletes the original file after renaming
      Returns:
      true if the file was renamed successfully
      Throws:
      IOException - if an I/O exception occurs
      FileDoesNotExistException - if the file does not exist
      FileIsADirectoryException - if the file is a directory
    • renameFile

      default boolean renameFile(File fileToRename, File newFileName, boolean delete) throws IOException, FileIsADirectoryException
      Renames the file, with an option to delete the original
      Parameters:
      fileToRename - the file to rename
      newFileName - the new filename
      delete - if true, deletes the original file after renaming
      Returns:
      true if the file was renamed successfully
      Throws:
      IOException - if an I/O exception occurs
      FileIsADirectoryException - if the file is a directory
    • renameFileWithSystemtime

      default File renameFileWithSystemtime(File fileToRename) throws IOException, FileIsADirectoryException
      Renames a file with the system time appended
      Parameters:
      fileToRename - the file to rename
      Returns:
      the renamed file with the system time
      Throws:
      IOException - if an I/O exception occurs
      FileIsADirectoryException - if the file is a directory
    • changeFilenameSuffix

      default boolean changeFilenameSuffix(File file, String newSuffix) throws IOException, FileDoesNotExistException, FileIsADirectoryException
      Changes the suffix of a filename. Example: test.dat to test.xxx
      Parameters:
      file - the file to change
      newSuffix - the new suffix, starting with a dot, e.g., ".xxx"
      Returns:
      true if the file was renamed successfully
      Throws:
      IOException - if an I/O exception occurs
      FileDoesNotExistException - if the file does not exist
      FileIsADirectoryException - if the file is a directory
    • forceToMoveFile

      default boolean forceToMoveFile(File srcFile, File destinationFile) throws IOException, FileIsADirectoryException
      Moves the specified source file to the given destination file
      Parameters:
      srcFile - the source file
      destinationFile - the destination file
      Returns:
      true if the file was moved successfully
      Throws:
      IOException - if an I/O exception occurs
      FileIsADirectoryException - if the source or destination is a directory
    • moveFile

      default boolean moveFile(File srcFile, File destDir) throws IOException, FileIsADirectoryException
      Moves the specified source file to the given destination directory
      Parameters:
      srcFile - the source file
      destDir - the destination directory
      Returns:
      true if the file was moved successfully
      Throws:
      IOException - if an I/O exception occurs
      FileIsADirectoryException - if the source or destination is a directory
    • renameFile

      default boolean renameFile(File fileToRename, String newFileNameWithoutAbsolutePath) throws IOException, FileIsADirectoryException, FileDoesNotExistException
      Renames the given file, allowing specification of a new file name without an absolute path
      Parameters:
      fileToRename - the file to rename
      newFileNameWithoutAbsolutePath - the new name for the file without absolute path
      Returns:
      true if the file was renamed successfully
      Throws:
      IOException - if an I/O exception occurs
      FileIsADirectoryException - if the file is a directory
      FileDoesNotExistException - if the file does not exist
    • renameFile

      default boolean renameFile(File fileToRename, File newFileName) throws IOException, FileIsADirectoryException
      This method renames a given file. For instance if we have a file which we want to rename with the path "/tmp/test.dat" to "/tmp/renamed.dat" then you call the method as follow: renameFile(new File("C://tmp//test.dat"), new File("C://tmp//renamed.dat"));
      Parameters:
      fileToRename - The file to rename.
      newFileName - The new name from the file.
      Returns:
      's true if the file was renamed otherwise false.
      Throws:
      IOException - Signals that an I/O exception has occurred.
      FileIsADirectoryException - the file is A directory exception