I have made a simple program with 4 classes. Organisefiles, ID3Test, Organise and Rename.
The Program is made to find mp3 files and change their names by looking at the ID3 tag.
The class Organisefiles is only the GUI and doesnt really do anything important. The Organise class loops through all files and sends every file to the Rename class.
The ID3Test class gets the ID3 tag from a file and is used by the Rename class.
All the classes work great except the Rename class.
im using the JID3 package
Here is the Rename class
import java.io.File;
import org.blinkenlights.jid3.ID3Tag;
I think the problem has to do with the renameTo method but i cant find anything that will help me.
If you know any already existing posts that may help me please put a link.
/**
* This Class renames the file with the pathout
* /first letter of artist/artist/artist - album/artist - album - tracknumber - title
*
* @author (David Falk)
* @version (2008-06-03)
*/
public class Rename
{
// instance variables
private File file;
private File pathout;
private String artist;
private String album;
private int tracknumber;
private String title;
private File path;
/**
* Constructor for objects of class Rename
*/
public Rename(File file, File pathout)
{
this.file = file;
this.pathout = pathout;
}
/**
* This method is called to start the process of renaming
*
*/
public void start() {
if(check()){
findfile();
//System.out.println(file.toString());
changefile();
}
else{
System.err.println(file.toString()+" is not a mp3 file");
}
}
/**
* This method checks if the file is a mp3 file
* @return true if mp3
*/
private boolean check(){
String name = file.getName();
boolean issame1 = name.endsWith("mp3");
boolean issame2 = name.endsWith("MP3");
boolean issame3 = name.endsWith("Mp3");
boolean issame4 = name.endsWith("mP3");
if(issame1 | issame2 | issame3 | issame4){
return true;
}
else {
return false;
}
}
/**
* This method creates an abstract path which is going to rename the mp3 file
*
*/
private void findfile(){
ID3Test id3 = new ID3Test(file);
artist = id3.getArtist();
album = id3.getAlbum();
tracknumber = id3.getTrackNumber();
title = id3.getTitle();
String artistfirstletter = String.valueOf(artist.charAt(0));
File path1 = new File(pathout, artistfirstletter);
File path2 = new File(path1, artist);
File path3 = new File(path2, (artist+" - "+album));
path = new File(path3, (artist+" - "+album+" - "+tracknumber+" - "+title));
}
/**
* This method renames the file
*
*/
private void changefile() {
System.out.println(path.toString());
System.out.println(file.renameTo(path));
}
}