Class RenameFileExtensions


  • public final class RenameFileExtensions
    extends java.lang.Object
    The class RenameFileExtensions helps you to rename files or directories.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String appendSystemtimeToFilename​(java.io.File fileToRename)
      Returns the filename from the given file with the systemtime.
      static java.lang.String appendSystemtimeToFilename​(java.io.File fileToRename, java.util.Date add2Name)
      Returns the filename from the given file with the systemtime.
      static java.util.List<java.io.File> changeAllFilenameSuffix​(java.io.File file, java.lang.String oldSuffix, java.lang.String newSuffix)
      Changes all the Filenames with the new Suffix recursively.
      static java.util.List<java.io.File> changeAllFilenameSuffix​(java.io.File file, java.lang.String oldSuffix, java.lang.String newSuffix, boolean delete)
      Changes all the Filenames with the new Suffix recursively.
      static boolean changeFilenameSuffix​(java.io.File file, java.lang.String newSuffix)
      Changes the suffix from the Filename.
      static boolean changeFilenameSuffix​(java.io.File file, java.lang.String newSuffix, boolean delete)
      Changes the suffix from the Filename.
      static boolean forceToMoveFile​(java.io.File srcFile, java.io.File destinationFile)
      Moves the given source file to the given destination file.
      static boolean moveFile​(java.io.File srcFile, java.io.File destDir)
      Moves the given source file to the destination Directory.
      static boolean renameFile​(java.io.File fileToRename, java.io.File newFileName)
      This method renames a given file.
      static boolean renameFile​(java.io.File fileToRename, java.io.File newFileName, boolean delete)
      This method renames a given file.
      static boolean renameFile​(java.io.File fileToRename, java.lang.String newFileNameWithoutAbsolutPath)
      This method renames a given file.
      static java.io.File renameFileWithSystemtime​(java.io.File fileToRename)
      Renames the given file and add to the filename the systemtime.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • appendSystemtimeToFilename

        public static java.lang.String appendSystemtimeToFilename​(java.io.File fileToRename)
        Returns the filename from the given file with the systemtime.
        Parameters:
        fileToRename - The file to rename.
        Returns:
        Returns the filename from the given file with the systemtime.
      • appendSystemtimeToFilename

        public static java.lang.String appendSystemtimeToFilename​(java.io.File fileToRename,
                                                                  java.util.Date add2Name)
        Returns the filename from the given file with the systemtime.
        Parameters:
        fileToRename - The file.
        add2Name - Adds the Date to the Filename.
        Returns:
        Returns the filename from the given file with the systemtime.
      • changeAllFilenameSuffix

        public static java.util.List<java.io.File> changeAllFilenameSuffix​(java.io.File file,
                                                                           java.lang.String oldSuffix,
                                                                           java.lang.String newSuffix)
                                                                    throws java.io.IOException,
                                                                           FileDoesNotExistException,
                                                                           FileIsADirectoryException
        Changes all the Filenames with the new Suffix recursively.
        Parameters:
        file - The file where to change the Filename with the new Suffix.
        oldSuffix - All files that have the old suffix will be renamed with the new Suffix.
        newSuffix - The new suffix.
        Returns:
        the list of files
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
        FileDoesNotExistException - If the file does not exist.
        FileIsADirectoryException - the file is A directory exception
      • changeAllFilenameSuffix

        public static java.util.List<java.io.File> changeAllFilenameSuffix​(java.io.File file,
                                                                           java.lang.String oldSuffix,
                                                                           java.lang.String newSuffix,
                                                                           boolean delete)
                                                                    throws java.io.IOException,
                                                                           FileDoesNotExistException,
                                                                           FileIsADirectoryException
        Changes all the Filenames with the new Suffix recursively. If delete is true its deletes the existing file with the same name.
        Parameters:
        file - The file where to change the Filename with the new Suffix.
        oldSuffix - All files that have the old suffix will be renamed with the new Suffix.
        newSuffix - The new suffix.
        delete - If its true than its deletes the existing file with the same name. But before it copys the contents into the new File.
        Returns:
        the list of files
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
        FileDoesNotExistException - If the file does not exist.
        FileIsADirectoryException - the file is A directory exception
      • changeFilenameSuffix

        public static boolean changeFilenameSuffix​(java.io.File file,
                                                   java.lang.String newSuffix,
                                                   boolean delete)
                                            throws java.io.IOException,
                                                   FileDoesNotExistException,
                                                   FileIsADirectoryException
        Changes the suffix from the Filename. Example: test.dat to test.xxx
        Parameters:
        file - The file to change.
        newSuffix - The new suffix. You must start with a dot. For instance: .xxx
        delete - If its true than its deletes the existing file with the same name. But before it copys the contents into the new File.
        Returns:
        true, if change filename suffix
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
        FileDoesNotExistException - If the file does not exist.
        FileIsADirectoryException - the file is A directory exception
      • forceToMoveFile

        public static boolean forceToMoveFile​(java.io.File srcFile,
                                              java.io.File destinationFile)
                                       throws java.io.IOException,
                                              FileIsADirectoryException
        Moves the given source file to the given destination file.
        Parameters:
        srcFile - The source file.
        destinationFile - The destination file.
        Returns:
        true if the file was moved otherwise false.
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
        FileIsADirectoryException - the file is A directory exception
      • moveFile

        public static boolean moveFile​(java.io.File srcFile,
                                       java.io.File destDir)
                                throws java.io.IOException,
                                       FileIsADirectoryException
        Moves the given source file to the destination Directory.
        Parameters:
        srcFile - The source file.
        destDir - The destination directory.
        Returns:
        true if the file was moved otherwise false.
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
        FileIsADirectoryException - the file is A directory exception
      • renameFile

        public static boolean renameFile​(java.io.File fileToRename,
                                         java.io.File newFileName)
                                  throws java.io.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:
        java.io.IOException - Signals that an I/O exception has occurred.
        FileIsADirectoryException - the file is A directory exception
      • renameFile

        public static boolean renameFile​(java.io.File fileToRename,
                                         java.io.File newFileName,
                                         boolean delete)
                                  throws java.io.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.
        delete - If true an attempt to copy the content from the file to rename to the new file and then delete the file to rename otherwise not.
        Returns:
        's true if the file was renamed otherwise false.
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
        FileIsADirectoryException - the file is A directory exception
      • renameFile

        public static boolean renameFile​(java.io.File fileToRename,
                                         java.lang.String newFileNameWithoutAbsolutPath)
                                  throws java.io.IOException,
                                         FileIsADirectoryException,
                                         FileDoesNotExistException
        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.
        newFileNameWithoutAbsolutPath - The new name from the file.
        Returns:
        's true if the file was renamed otherwise false.
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
        FileIsADirectoryException - the file is A directory exception
        FileDoesNotExistException - the file does not exist exception
      • renameFileWithSystemtime

        public static java.io.File renameFileWithSystemtime​(java.io.File fileToRename)
                                                     throws java.io.IOException,
                                                            FileIsADirectoryException
        Renames the given file and add to the filename the systemtime.
        Parameters:
        fileToRename - The file to rename.
        Returns:
        Returns the renamed file from the given file with the systemtime.
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
        FileIsADirectoryException - the file is A directory exception