net.sourceforge.jaulp.file.rename
Class RenameFileUtils

java.lang.Object
  extended by net.sourceforge.jaulp.file.rename.RenameFileUtils

public class RenameFileUtils
extends java.lang.Object

The Class RenameFileUtils helps you to rename files or directories.

Version:
1.0
Author:
Asterios Raptis

Constructor Summary
RenameFileUtils()
           
 
Method Summary
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 destDir)
          Moves the given source file to the destination Directory.
static java.lang.String getAbsolutPathWithoutFilename(java.io.File file)
          Gets the absolut path without the filename.
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
 

Constructor Detail

RenameFileUtils

public RenameFileUtils()
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.
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
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< file>
Throws:
java.io.IOException - Signals that an I/O exception has occurred.
FileDoesNotExistException - If the file does not exist.

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
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< file>
Throws:
java.io.IOException - Signals that an I/O exception has occurred.
FileDoesNotExistException - If the file does not exist.

changeFilenameSuffix

public static boolean changeFilenameSuffix(java.io.File file,
                                           java.lang.String newSuffix)
                                    throws FileNotRenamedException,
                                           FileDoesNotExistException,
                                           java.io.IOException
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.
java.io.IOException - Signals that an I/O exception has occurred.

changeFilenameSuffix

public static boolean changeFilenameSuffix(java.io.File file,
                                           java.lang.String newSuffix,
                                           boolean delete)
                                    throws java.io.IOException,
                                           FileDoesNotExistException
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.

getAbsolutPathWithoutFilename

public static java.lang.String getAbsolutPathWithoutFilename(java.io.File file)
Gets the absolut path without the filename.

Parameters:
file - the file.
Returns:
the absolut path without filename.

moveFile

public static boolean moveFile(java.io.File srcFile,
                               java.io.File destDir)
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.

forceToMoveFile

public static boolean forceToMoveFile(java.io.File srcFile,
                                      java.io.File destDir)
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.

renameFile

public static boolean renameFile(java.io.File fileToRename,
                                 java.io.File newFileName)
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.

renameFile

public static boolean renameFile(java.io.File fileToRename,
                                 java.io.File newFileName,
                                 boolean delete)
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.

renameFile

public static boolean renameFile(java.io.File fileToRename,
                                 java.lang.String newFileNameWithoutAbsolutPath)
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.

renameFileWithSystemtime

public static java.io.File renameFileWithSystemtime(java.io.File fileToRename)
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.


Copyright © 2010. All Rights Reserved.