TrackNo - Title.mp3
But my track number was 00, for all of the songs. So I had all the songs with the following format.
00 - Beat It.mp3
I didn't like that format, I just wanted the song name. I knew it would take atleast a day for me to rename all the songs manually. Only thing came to my mind was, SHELL SCRIPT. I am not very expert in shellscripting but with Window's Vista, all I could use is DOS. Did few google search and wasn't successfull with the google search, I decided to do my own multiple files renamer. Since, Java provides most of the functionality I needed to do this program, I went with Java.
Here is the code below. Just run the program like this (don't change any code, uncomment anything) and see if the output of your renamed files are correct. If its correct then you could uncomment the bolded 2 lines of code which will actually rename the original files.
import java.awt.FlowLayout;
import java.io.File;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
public class FilesRenamer
{
public static void main(String[] args) throws Exception
{
JTextArea text = new JTextArea(15, 30);
text.setText("Original Files:\nRenamed Files:\n\n");
File selected[];
JScrollPane scroll = new JScrollPane(text);
JFileChooser chooser = new JFileChooser("C:\\Users\\Owner\\Music");
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setMultiSelectionEnabled(true);
JFrame f = new JFrame("Multiple Files Renamer");
f.setLayout(new FlowLayout());
f.add(scroll);
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
f.setSize(500, 600);
f.setVisible(true);
int returnVal = chooser.showOpenDialog(f);
if (returnVal == JFileChooser.APPROVE_OPTION)
{
selected = chooser.getSelectedFiles();
if (selected.length == 1 && !selected[0].exists())
JOptionPane.showMessageDialog(null,
"File does not exists!", "Alert!",
JOptionPane.ERROR_MESSAGE);
else
{
for (int i=0; i<selected.length; i++)
{
text.append(selected[i].toString() + "\n");
String temp = newname(selected[i]);
if (temp != null)
{
text.append(temp + "\n\n");
}
}
}
}
chooser.setSelectedFile(null);
}
public static String newname(File fullpath)
{
String newfilename = fullpath.getName();
newfilename = newfilename.substring(5);
File filedir = new File (fullpath.getParentFile() + "\\"
+ newfilename);
//if (full.renameTo(filedir))
return filedir.toString();
//return null;
}
}
Let's say if you want to play with extension, such as to make jpg to jpeg or change from mp3 to wma then add the following function into the code.public static String extension(String filename)
{
String justFileName = filename.substring(0, filename.lastIndexOf('.'));
String ext = filename.substring(filename.lastIndexOf('.'));
ext = ".mp3";
String newfilename = justFileName+""+ext;
return(newfilename);
}
and change the newname function to the following.public static String newname(File fullpath)
{
String newfilename = fullpath.getName();
//newfilename = newfilename.substring(5);
newfilename = extension(newfilename);
File filedir = new File (fullpath.getParentFile() + "\\" + newfilename);
//if (full.renameTo(filedir))
return filedir.toString();
//return null;
}


