-
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
-
Can you use the File class's renameTo method?
-
Thanks a lot, its working now.
Similar Threads
-
By Drew_gable in forum VB Classic
Replies: 2
Last Post: 05-26-2006, 03:00 PM
-
By airrazor in forum Java
Replies: 11
Last Post: 11-06-2005, 10:18 AM
-
By Rob Teixeira in forum .NET
Replies: 15
Last Post: 05-31-2002, 03:30 PM
-
By Martin in forum VB Classic
Replies: 22
Last Post: 12-03-2001, 03:53 AM
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks