renaming multiples files in a directory by removing similar charecters
Hi.
I have got a problem. I have got 100 mp3 files in a directory. All the mp3 file names start with E_. I want to programatically rename all these mp3 files by removing the charecters E_ from the file name. I used the below program but it is not working. Iam using java 1.6.
import java.io.File;
import java.io.IOException;
public class Ls {
public static void main(String argh_my_aching_fingers[]) {
String[] dir = new java.io.File("f:\\songs\\tar\\").list(); // Get list of names
java.util.Arrays.sort(dir); // Sort it (Data Structuring chapter))
for (int i = 0; i < dir.length; i++)
{
System.out.println(dir); // Print the list
String fileName = dir;
File f = new File("f:\\songs\\tar\\filename");
int length = fileName.length();
String newFileName=fileName.substring(2,length-4);
System.out.println("newFileName="+newFileName);
f.setWritable(true);
System.out.println("can be renamed"+f.canWrite());
System.out.println("the name change is"+f.renameTo(new File(newFileName)));
}
OUTPUT
- Run Java File -
E_ippud.mp3
newFileName=ippud
can be renamedfalse
the name change isfalse
Output completed (0 sec consumed) - Normal Termination
iam even setting the file property to writable. I dont know why it is not renaming the files.?
please help me. i

