Package io.github.astrapi69.file.rename
Class RenameFileExtensions
java.lang.Object
io.github.astrapi69.file.rename.RenameFileExtensions
The class
RenameFileExtensions
helps you to rename files or directories.-
Method Summary
Modifier and TypeMethodDescriptionstatic String
appendSystemtimeToFilename
(File fileToRename) Returns the filename from the given file with the systemtime.static String
appendSystemtimeToFilename
(File fileToRename, Date add2Name) Returns the filename from the given file with the systemtime.changeAllFilenameSuffix
(File file, String oldSuffix, String newSuffix) Changes all the Filenames with the new Suffix recursively.changeAllFilenameSuffix
(File file, String oldSuffix, String newSuffix, boolean delete) Changes all the Filenames with the new Suffix recursively.static boolean
changeFilenameSuffix
(File file, String newSuffix) Changes the suffix from the Filename.static boolean
changeFilenameSuffix
(File file, String newSuffix, boolean delete) Changes the suffix from the Filename.static boolean
forceToMoveFile
(File srcFile, File destinationFile) Moves the given source file to the given destination file.static boolean
Moves the given source file to the destination Directory.static boolean
renameFile
(File fileToRename, File newFileName) This method renames a given file.static boolean
renameFile
(File fileToRename, File newFileName, boolean delete) This method renames a given file.static boolean
renameFile
(File fileToRename, String newFileNameWithoutAbsolutPath) This method renames a given file.static File
renameFileWithSystemtime
(File fileToRename) Renames the given file and add to the filename the systemtime.
-
Method Details
-
appendSystemtimeToFilename
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
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 List<File> changeAllFilenameSuffix(File file, String oldSuffix, String newSuffix) throws 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:
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 List<File> changeAllFilenameSuffix(File file, String oldSuffix, String newSuffix, boolean delete) throws 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:
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(File file, String newSuffix) throws FileNotRenamedException, FileDoesNotExistException, IOException, 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- Returns:
- true if the file was renamed.
- Throws:
FileNotRenamedException
- If the file could not renamed.FileDoesNotExistException
- If the file does not exist.IOException
- Signals that an I/O exception has occurred.FileIsADirectoryException
- the file is A directory exception
-
changeFilenameSuffix
public static boolean changeFilenameSuffix(File file, String newSuffix, boolean delete) throws 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: .xxxdelete
- 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:
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(File srcFile, File destinationFile) throws 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:
IOException
- Signals that an I/O exception has occurred.FileIsADirectoryException
- the file is A directory exception
-
moveFile
public static boolean moveFile(File srcFile, File destDir) throws 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:
IOException
- Signals that an I/O exception has occurred.FileIsADirectoryException
- the file is A directory exception
-
renameFile
public static 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
-
renameFile
public static boolean renameFile(File fileToRename, File newFileName, boolean delete) 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.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:
IOException
- Signals that an I/O exception has occurred.FileIsADirectoryException
- the file is A directory exception
-
renameFile
public static boolean renameFile(File fileToRename, String newFileNameWithoutAbsolutPath) throws 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:
IOException
- Signals that an I/O exception has occurred.FileIsADirectoryException
- the file is A directory exceptionFileDoesNotExistException
- the file does not exist exception
-
renameFileWithSystemtime
public static File renameFileWithSystemtime(File fileToRename) throws 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:
IOException
- Signals that an I/O exception has occurred.FileIsADirectoryException
- the file is A directory exception
-