Remove specific characters from file name if exists

There was many songs with the name of websites from which they were downloaded. i wanted to remove the name of websites from the name of song. Just for cleanness of name appearances in music player. I made java program for that.


import java.io.File;

public class StringRepeat {
static File f[] = new File("c:/users/thesa/desktop/new folder/").listFiles();
static String str[] = new String[f.length];

public static void main(String agrs[]) {

for (int i = 0; i < f.length; i++) {
str[i] = (f[i].getName());
StringBuffer sb = new StringBuffer(str[i]);
int x = (sb.lastIndexOf("www.djmaza.com"));

if (x > 0) {
System.out.println("File before renaming " + sb);
sb.delete(x, x + 3);
System.out.println("File after renaming " + sb);
System.out.println("result from getparent " + f[i].getParent());
System.out.println("For loop end");
File renamed = new File(f[i].getParent() + "/ " + sb);
f[i].renameTo(renamed);
} else {
System.out.println("no xyz found for " + f[i].getAbsolutePath());
}
}
}

}

Comments

Popular posts from this blog

How to check if two Strings are anagrams of each other?

Multimedia search engine using python

How to sort String array by length of each string present in an array