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
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?
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);
}
}
}
Re: Append and Renaming of File
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?
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);
}
}
}
Re: Append and Renaming of File
Also posted in the OTN forums: link.
kind regards,
Jos