
Hi,
I have number of files in a directory. Files are named as: 1DeoyaRohit0705$.mp4,2DeoyaRohit0705$.mp4, 3_DeoyaRohit0705$.mp4. ....
Now I wanted to rename these files as: 1RohitBBorse.mp4, 2RohitBBorse.mp4, 3_RohitBBorse.mp4, ....
Please suggest me through java program how I can fulfill this requirement. Instead of going one by one I want to do this at one shot through Java program.
Thanks in advance. :)

import java.io.*;
class RenameFiles
{
public static String getFileNameWithoutExtension(String fileName) {
File file = new File(fileName);
int index = file.getName().lastIndexOf('.');
if (index>0&& index <= file.getName().length() - 2 ) {
System.out.println("Filename without Extension: "+file.getName().substring(0, index));
}
return "";
}
public static void main(String[] args){
String files[]={"c:/1Angelrose0705$.jpg","c:/2Angelrose0705$.jpg","c:/3Angelrose0705$.jpg","c:/4Angelrose0705$.jpg"};
File oldfile[]=new File[files.length];
String st[]=new String[files.length];
for(int i=0;i<oldfile.length;i++){
oldfile[i]=new File(files[i]);
int index = oldfile[i].getName().lastIndexOf('.');
if (index>0&& index <= oldfile[i].getName().length() - 2 ) {
st[i]=oldfile[i].getName().substring(0, index);
}
}
File newfile[] = new File[files.length];
String filename[]=new String[files.length];
for(int i=0;i<files.length;i++){
filename[i]=st[i].replace("Angelrose0705$","RohitBBorse");
newfile[i]=new File(filename[i]+".jpg");
}
for(int i=0;i<files.length;i++){
boolean Rename = oldfile[i].renameTo(newfile[i]);
if(Rename){
System.out.println("Renamed Successfully!");
}
}
}
}

Thanks friend :)
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.