import java.io.*;
import java.text.*;
import java.util.*;
/***
 * renames files ending with ".jpg" to be prepended with the Date
 * "DC108.JPG" becomes "2002-01-03-DC108.JPG"
 * This is useful for getting digital camera images into the name format I like
 * @author Mitch Fincher, mitchfincher@yahoo.com
**/
class DateRenamer {

public static void main(String[] args) {
	
    File thisDir = new File(".");
    //lets get the list of files
    String files[] = thisDir.list(new FilenameFilter() {
	    public boolean accept(File dir, String name) {
		return(name.toUpperCase().endsWith(".JPG") && (! name.startsWith("200"))); 
	    }
	}
				  );

    String oldFilename;
    File oldFile;
    Date date;
    String dateString;
    String newFilename;
    File newFile;

    SimpleDateFormat formatter
	= new SimpleDateFormat ("yyyy-MM-dd-");
    for(int i=0;i<files.length;i++) {
	try {
	    oldFilename = files[i];
	    oldFile = new File(oldFilename);
	    date = new Date(oldFile.lastModified());
	    dateString = formatter.format(date);
	    newFilename = dateString+oldFilename;
	    newFile = new File(newFilename);
	    System.out.print("Processing: " + oldFilename);
	    
	    boolean ok = oldFile.renameTo(newFile);
	    if(!ok) {
		System.out.print("** failed operation trying --  " );
	    }
	    System.out.println(" renamed to " + newFilename);
	    
	} catch (Exception e) {
	    System.out.println("e: " + e);
	    e.printStackTrace();
	}
    }
} //end of main

}

    
