Having trouble with the renameTo() method in Windows

Hi all,
The below code works perfectly well in netbeans but as shown as I try to call it from cmd prompt I get issues.
The below code is designed to move or delete log files from one area or another.
now if i try to delete the logs from command prompt I have no problem.
However when I tried to move the files by doing renameTo() I get a false back. And as this method seems to have no relevant error message, I am at a loss....
Now I have checked the permissions, this is not a problem (all users can edit the files, if I can't edit them why will let me delete them?), I have checked to make sure no duplicate files exist and they don't. i have also tried to move the files to different locations, same problem. The files are definitely not open.
I need the below to work on 1.5 due to compatibility issues with other programs.
Any ideas?
public class Main {
     * @param args the command line arguments
     * args[0] = Directory where files are to be processed from
     * args[1] = file extension to process
     * args[2] = Number of days to limit on. IE 31 means all files older than 31 days
     * args[3] = location of log file
     * args[4] = del/move. if del, files are deleted. if move, files are moved.
     * args[5] = Location of the new file. only applicable if file is moved.
    public static final String newLine = System.getProperty("line.separator").toString();
    public static void main(String[] args) {
        try {
            File file = new File(args[0]);
            FileNameFilter fileFilter = new FileNameFilter(args[1]);
            int days = Integer.parseInt(args[2]);
            File[] children = file.listFiles(fileFilter);
            // longs required because int overflow limit reached.
            long daysAgoPart1 = 1000 * 60 * 60;
            long daysAgoPart2 = 24 * days;
            long daysAgoPart3 = daysAgoPart1 * daysAgoPart2;
            long daysAgo = new Date().getTime() - (daysAgoPart3);
            // System.out.println(daysAgoPart3);
            // System.out.println(new Date().getTime());
            // System.out.println(daysAgo);
            // System.out.println(new Date().toString());
            Date limitDate = new Date(daysAgo);
            // System.out.println(new Date(new Date().getTime()).toString());
            //  System.out.println(limitDate.toString());
            for (int i = 0; i < children.length; i++) {
                if (children.lastModified() - limitDate.getTime() < 0) {
if (args[4].compareTo("del") == 0) {
printLog("Deleted file: " + children[i].getAbsolutePath(), args[3]);
children[i].delete();
} else if (args[4].compareTo("move") == 0){
String fileName = children[i].getAbsolutePath();
if (!children[i].canRead()){
printLog("Can't read: " + fileName, args[3]);
} else if (!children[i].canWrite()){
printLog("Can't write: " + fileName, args[3]);
if( (children[i].renameTo(new File(args[5] + children[i].getName())))){
printLog("Moved file "+ fileName, args[3]);
} else {
printLog("Failed to move file "+ fileName, args[3]);
} catch (Exception err) {
printLog(err.toString(), args[3]);
public static void printLog(String message, String logLoc) {
try {
File errLog = new File(logLoc);
FileWriter errFW = new FileWriter(errLog, true);
errFW.append(new Date().toString() + " " + message);
errFW.append(newLine);
errFW.close();
} catch (IOException errFWException) {
}Edited by: enema0007 on Sep 2, 2009 8:27 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

right I think I have worked out what I am doing wrong I think.....
I am calling the code with:
java -jar "deleteLogs.jar" "D:\TADDM" ".rar" 31 "D:\Working Files\deleteFilesLog.log" "move" "D:\Working Files\"
However when I go to create file its giving me:
D:\Working Files"logs.rar
Which is clearly not the correct file name....
So why is it removing the \ and not the "?

Similar Messages

  • Is PE10 compatible with Windows 8? Having trouble with the organizer.

    Is PE10 compatible with Windows 8? Having trouble with the organizer

    It does sound very Watch Folders-esque, however, it seems strange that there are many folders involved. Are all the folders under a single parent folder perhaps? If so, you could try renaming or moving that folder. Additionally, to clarify, all 60 files are images, correct?
    Additionally, you can try creating a new catalog, just to see if that lets you in. Hold down the Shift key while launching the Organizer. If you get the timing right, the Catalog Manager will appear.

  • I have a Mac, IPad, I phones, and 2 Windows Vista Pcs and I'm having trouble with the Windows Laptop staying connected.  I have to re-boot after and extended period of time please help

    I have a Mac, IPad, I phones, and 2 Windows Vista Pcs and I'm having trouble with the Windows Laptop staying connected.  I have to re-boot after an extended period of time please help.  Thanks!

    I have a Mac, IPad, I phones, and 2 Windows Vista Pcs and I'm having trouble with the Windows Laptop staying connected.  I have to re-boot after an extended period of time please help.  Thanks!

  • I'm having trouble with the folder "Automatically add" function. She opens a folder "not added". My machine is a Vaio with Windows 7 home basic antivirus using Microsoft. Regards.

    I'm having trouble with the folder "Automatically add" function. She opens a folder "not added". My machine is a Vaio with Windows 7 home basic antivirus using Microsoft. Regards.

    Its a 64 bits.

  • Problem with the renameTO method in the Linux environment

    Hi
    I got a problem with the renameTO method in the Linux environment. The file is not moving.
    This method is returning false. the same code executed successfully in Windows environment.
    Can anyone give some fix to this one or an alternate solution to move the files in both windows and Linux.
    boolean success;
    File root = new File(tempPath);
                   File f = new File(root, phyFileName);
                   File dest = new File(targetPath);
    success = f.renameTo(new File(dest, actualFileName));actualFileName = 400.doc
    dest = /home/jboss-4.0.3/axsscm_1.0/axsscmDocuments/xchange/fileup/fshare/PO/1786

    JITHENDRA wrote:
    Thanks for the prompt replyNo problem.
    >
    Can u solve the below doubt.
    Will renameTo method wont work in Linux? If so why?Did you not read what I said? I suspect you are trying to rename a file so that it actually has to be moved to a different volume (partition or hard disk) so it won't work. One would have the same problem on Windows trying to rename a file on the c: drive to a name on the d: drive.
    >
    >
    Can u give a sample or good link to do the above work which works fine in all environments.?Just follow the pseudo code I gave. 15 minutes work.

  • Having trouble with the sound!!!

    Recently I'm having trouble with the way the music played by the iTunes sounds! I first thought I have moved the equalizer's settings but I didn't. Music sounds funny with echo.... I'm sure that's a problem of the iTunes because I have played the same song using Windows Media player and it sounds fine! Can someone help me please???!!!!

    Can I just check.
    You went to System Preferences (The Square grey icon with an Apple and Lightswitch or from the Blue apple menu top left) ?
    Form the List of Preference Panes you choose Sound far right of the second row ?
    And the Sound Effects tab in there ?
    There should be a volume control for them in there and it need moving to the right.
    10:52 PM Monday; January 15, 2007

  • Having trouble with the most simple of things: Static IP

    I am having trouble with the most simple of things: Static IP.
    I am working in Windows Server 2008 R2 SP1.
    "Control Panel\Network and Internet\Network and Sharing Center\Local Area Connections>Properties>Internet Protocol Version 4 (TCP/IPv4) and Internet Protocol Version 6 (TCP/IPv6)"
    IPv4: I have went to "ipconfig /all" and found the "preferred" IP Address and the Default Gateway. 
    Assign DNS Servers?
    IPv6: I used "netsh interface ipv6 show address level=verbose" and found 3 usable IPv6 IPs.
    Assign IP Address, Default Gateway and DNS Servers?

    What is the question?
    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows]
    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees , and confers no rights.

  • I'm having trouble with the install of Adobe digital editions

    I'm having trouble with the install of Adobe digital editions, how can we fix this? It will begin to dowload it says complete but stops there, no other prompts and if you click the close button it appears that it begins to delete itself. How can i fix this issue?

    Hi,
    It would be great, if you provide us with the environment where you are trying the install the ADE.
    For Example,
    - ADE version
    - Operating System
    - Anti-Virus you are using.
    - did you logged in as Admin or user on your computer.
    (*any error message you are able to locate/view  from Event Viewer- If using Windows OS)
    Regards,
    Yuvraj.

  • I am having trouble with the Canon Image browser ex.l

    i am having trouble with the canon image browser ex.After sevearl downloads i eventually got past the 80% mark.it is now downloaded.however as soon as I click on it it opens up and then a message comnes upm saying that there is a problem and windows is searching for the problem.it then closes the oprogramme down..Any help would be appreciated 

    I am having the same problem and have contacted Canon, they've answered me several times with things to try but nothing they've told me to try helps. It looks like they are going shrug, scratch their heads soon and  pass the buck to Microsoft or HP my comp make .
    I have a Windows 8.1 OS, 64 bit comp.

  • Having trouble with the security questions for iTunes.  Tried to reset them, but the mail from Apple never comes . . .

    Having trouble with the security questions for iTunes.  Tried to reset them, but the mail from Apple never comes . . .

    You need to ask Apple to reset your security questions; ways of doing so include clicking here and picking a method for your country, and filling out and submitting this form.
    (96290)

  • I am having trouble with the "numbers" app on my MacBook Air. I go to print my document and that works just fine. I cannot however return to the document after printing. What do I have to do?

    I am having trouble with the "numbers" app on my MacBook Air. I go to print my document and that works just fine. I cannot however return to the document after printing. What do I have to do?

    RR,
    Not to worry, you're not the first to expect Print to finish by returning you to the edit mode. The thing is that Printing is so hit and miss with this version of the app, you will probably want to stay in the Print window for more than one attempt.
    Jerry

  • I need any help i can get, im having trouble with the app find my iphone. I have lost my iphone, checked on the computer, and somehow, took it away so how do i get it back??

    Help
    I need any help i can get, im having trouble with the app find my iphone. I have lost my iphone, checked on the computer, and somehow, took it away so how do i get it back??

    If you are saying that after signing into iCloud it is telling you device is not found, it could be for any number of reasons. If the battery is dead, if the SIM has been removed, or if someone else has the phone and they have restored it, it will not be shown. Also, if you located it once and then sent a remote wipe, it disables the abililty to locate the phone with Find My iPhone.

  • I am having trouble with the Jpeg icons and also now thumbnails not being visable in bith teh Apple finder and now also Adobe Bridge. Can anyone shed any light on this ?

    I am having trouble with the Jpeg icons and also now thumbnails not being visable in bith teh Apple finder and now also Adobe Bridge. Can anyone shed any light on this ?

    Argh - once again, I find my solution right after posting this. Left out one modification to the SWIG script, now it runs in 29 seconds vs C 16 seconds, I can live with that.

  • I am having trouble with the cache in bridge.  When i open I get a message saying bridge has encountered a problem reading the cache try purging in the central cache to correct the situation.  I did that but now when I try to get to the folders where my p

    I am having trouble with the cache in bridge.  When i open I get a message saying bridge has encountered a problem reading the cache try purging in the central cache to correct the situation.  I did that but now when I try to get to the folders where my photos are stored bridge never gets to where I can work.  The message appears "building criteria" and I get an endless loop on the lower left panel.  How do I correct?

    You correct it by leaving Bridge alone until it finishes rebuilding its cache, overnight if necessary.

  • I'm having trouble with the develop module in LR5.4. Any adjustments are taking effect, but only viewable in the filmstrip, not on the main photo. The navigator will go grey, as does the main area too. This applies to all edits done in develop module. I h

    I'm having trouble with the develop module in LR5.4. Any adjustments are taking effect, but only viewable in the filmstrip, not on the main photo. The navigator will go grey, as does the main area too. This applies to all edits done in develop module. I have posted several times on the forum with no responses to address this, and have seen others with the same issue. I have even gone as far as to do a complete re-install of LR5, with no success. I'm at a loss, and I depend on it for so much editing. Please help.

    Reset your preferences file: Resetting (or 'Trashing') the Lightroom Preferences file - Lightroom Forums
    Report back if that doesn't work.

Maybe you are looking for

  • Creation of a purchase order triggers the event ReleaseStepCreated twice

    Hello, I tried to use the standard workflow for the approval of a purchase order and noticed that i am receiving twice the same mail. As you know, the workflow is triggered by the event ReleaseStepCreated. After I created a purchase order, i saw that

  • Analyze error in RWB

    After some performace testing I have an error in rwb (sender ) Transmitting the message to endpoint http://xi:8000/sap/xi/engine?type=entry using connection AFW failed, due to: Received HTTP response code 500 : Internal Server Error. smq1/smq2 doesn'

  • Existing session is becoming null when returning from jsp

    Hi Guys ! I have an urgent requirement to meet in few days from now and got stuck with session problem in servlet. Scenario :- For the first time when i call a servlet a new sessoin is created and after some validations i forward to a jsp which has s

  • Having multiple resultsets open at the same time

    Hi, I have the following piece of code to populate multiple resultsets returned by a call to a stored procedure in Sybase. int l_noOfResultSetsReturned = 0; int l_nextResultSetToPopulate = 1; boolean l_isResultSet = l_CallableStatement.execute();    

  • Boot camp process. MacBook Pro cannot fid a bootable disk?

    boot camp process. MacBook Pro cannot fid a bootable disk?