Results 1 to 6 of 6
Thread: Append and Renaming of File
- 07-22-2012, 09:13 AM #1
Member
- Join Date
- Jul 2012
- Posts
- 3
- Rep Power
- 0
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
- 07-22-2012, 10:57 AM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
- 07-22-2012, 12:27 PM #3
Member
- Join Date
- Jul 2012
- Posts
- 3
- Rep Power
- 0
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);
}
}
}
- 07-22-2012, 01:21 PM #4
Re: Append and Renaming of File
Why do they call it rush hour when nothing moves? - Robin Williams
- 07-22-2012, 01:28 PM #5
Member
- Join Date
- Jul 2012
- Posts
- 3
- Rep Power
- 0
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); } } }
- 07-22-2012, 02:44 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
Re: Append and Renaming of File
Also posted in the OTN forums: link.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
how to compare two csv file and append the result of each line in the same csv file
By shaal89 in forum New To JavaReplies: 2Last Post: 04-02-2012, 01:59 PM -
Renaming a file
By sunde887 in forum New To JavaReplies: 9Last Post: 06-14-2011, 08:23 AM -
File renaming help
By themulator in forum New To JavaReplies: 3Last Post: 04-01-2011, 05:24 AM -
How to Append in file ?
By Hippo in forum New To JavaReplies: 2Last Post: 03-19-2010, 01:50 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks