Results 1 to 6 of 6
  1. #1
    abhinav01 is offline Member
    Join Date
    Jul 2012
    Posts
    3
    Rep Power
    0

    Post Append and Renaming of File

    Hi,

    I have a folder where i have image files having names in format 001A0110.676

    My requirement is to rename these files. I have to remove . and append IW to the start of all filenames. So my filename should be like IW001A0110676

    Please suggest how to implement this through java.

    Thanks
    Abhinav

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default Re: Append and Renaming of File

    Java 6 or 7 ? :P

    There is a class named File with the method renameTo!
    The only thing you have to do are string operations! Do you have problems here?

  3. #3
    abhinav01 is offline Member
    Join Date
    Jul 2012
    Posts
    3
    Rep Power
    0

    Default Re: Append and Renaming of File

    Thanks for reply. I am first trying to append IW to names. I have written below code can you tell me where i am getting it wrong?

    public static void main(String args[])
    {

    try {





    // inputpath = args[0];
    // outputpath = args[1];

    inputpath = "C:\\Isuzu_CS_Test";
    outputpath = "C:\\Isuzu_CS_Test_out";



    File f = new File(inputpath);


    String[] catname = f.list();


    System.out.println("Total Files Available To Rename = "+catname.length);
    File[] listOfFiles = f.listFiles();
    for (int j = 0; j < listOfFiles.length; j++) {
    if (listOfFiles[j].isFile()) {
    String text = listOfFiles[j].getName();
    System.out.println(text);
    File F5=listOfFiles[j];
    System.out.println("F5 ="+F5);
    String text2="IW"+text;
    File F6= new File(text2);

    System.out.println(F6);

    F5.renameTo(F6)

    }}




    }catch (Exception e){
    System.out.println("Exception in Main :: "+e);
    System.exit(1);
    }

    }
    }

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Append and Renaming of File

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    abhinav01 is offline Member
    Join Date
    Jul 2012
    Posts
    3
    Rep Power
    0

    Default Re: Append and Renaming of File

    Thanks for reply. I am first trying to append IW to names. I have written below code can you tell me where i am getting it wrong?

    Java Code:
    public static void main(String args[])
    {
    
    try {
    
    
    
    inputpath = "C:\\Isuzu_CS_Test";
    
    
    
    File f = new File(inputpath);
    
    
    String[] catname = f.list();
    
    
    System.out.println("Total Files Available To Rename = "+catname.length);
    File[] listOfFiles = f.listFiles();
    for (int j = 0; j < listOfFiles.length; j++) {
    if (listOfFiles[j].isFile()) {
    String text = listOfFiles[j].getName();
    System.out.println(text);
    File F5=listOfFiles[j];
    System.out.println("F5 ="+F5);
    String text2="IW"+text;
    File F6= new File(text2);
    
    System.out.println(F6);
    
    F5.renameTo(F6)
    
    }}
    
    
    
    
    }catch (Exception e){
    System.out.println("Exception in Main :: "+e);
    System.exit(1);
    }
    
    }
    }

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,336
    Blog Entries
    7
    Rep Power
    20

    Default Re: Append and Renaming of File

    Also posted in the OTN forums: link.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Replies: 2
    Last Post: 04-02-2012, 01:59 PM
  2. Renaming a file
    By sunde887 in forum New To Java
    Replies: 9
    Last Post: 06-14-2011, 08:23 AM
  3. File renaming help
    By themulator in forum New To Java
    Replies: 3
    Last Post: 04-01-2011, 05:24 AM
  4. How to Append in file ?
    By Hippo in forum New To Java
    Replies: 2
    Last Post: 03-19-2010, 01:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •