Friday, April 10, 2009

moving file code

private static void moveFile(String a_FileName, String a_LocalPath) throws Exception
{
/** Move the file to an archive or delete it **/
/** The standard rivermine Util for this crashes and burns b/c this particular file has no . **/

/** Make new file out current file **/
File file = new File(a_FileName);

/** Make new file out desired directory **/
File dir = new File(a_LocalPath + File.separator + "archive" + File.separator);
dir.mkdir(); // have to call this to instantiate the folder if not exists
// otherwise, renameTo() below will NOT work.

/** Move the actual file to the directory **/
boolean success = file.renameTo(new File(dir, file.getName()));
if (success)
{
s_log.info("File Archived Succesfully to - " + dir.toString() + File.separator
+ file.getName());
}
else
{
s_log.info("File Not Archived Succesfully - please move it to - " + dir.toString());
}
}