Rename files with a given string


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Rename files with a given string

  1. #1
    Join Date
    Dec 2006
    Posts
    16

    Rename files with a given string

    Can anyone please help with the following code. I need to rename files with a given string. My code is:

    import java.io.File;

    public class RenameFile
    {
    public RenameFile()
    {
    }

    void naming(File destFiles, String rename)
    {
    System.out.println("destFiles:"+destFiles.getName());
    //output: destFiles:C:\temp\store\test.abc
    //output: destFiles:C:\temp\store\test.def
    //output: destFiles:C:\temp\store\test.ghi
    System.out.println("rename:"+rename);
    //output: rename:amnr

    String name=destFiles.getName().toString();
    System.out.println("name:"+name);
    //output: name:test.abc
    //output: name:test.def
    //output: name:test.ghi

    String ren="";
    ren=name.replaceAll(name,rename);
    System.out.println("ren:"+ren);
    //output: ren:amnr
    }
    }

    My files I am getting from "destFiles" are:
    C:\temp\store\test.abc
    C:\temp\store\test.def
    C:\temp\store\test.ghi


    which I need to rename as:
    C:\temp\store\amnr.abc
    C:\temp\store\amnr.def
    C:\temp\store\amnr.ghi

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    Can you use the File class's renameTo method?

  3. #3
    Join Date
    Dec 2006
    Posts
    16
    Thanks a lot, its working now.

Similar Threads

  1. Importing txt files.
    By Drew_gable in forum VB Classic
    Replies: 2
    Last Post: 05-26-2006, 03:00 PM
  2. if statements
    By airrazor in forum Java
    Replies: 11
    Last Post: 11-06-2005, 10:18 AM
  3. App Object
    By Rob Teixeira in forum .NET
    Replies: 15
    Last Post: 05-31-2002, 03:30 PM
  4. Writing in HKEY_LOCAL_MACHINE...Access is denied
    By Martin in forum VB Classic
    Replies: 22
    Last Post: 12-03-2001, 03:53 AM
  5. Database problems
    By Robert Rieth in forum VB Classic
    Replies: 1
    Last Post: 04-11-2000, 03:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center