package cc.glsn.v15; import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; public class FileDateImport { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { if (args.length < 2) { System.out.println("Syntax: "); return; } new FileDateImport(args[0],args[1]); } public FileDateImport(String srcDir, String dstDir) throws IOException { File f_src=new File(srcDir); SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); for(File f : f_src.listFiles()) { Date d=new Date(f.lastModified()); String newDstDir=dstDir + "/" + sdf.format(d); File newDir=new File(newDstDir); newDir.mkdir(); if (!newDir.exists()) { throw new IOException("Unable to create dir: " + newDstDir); } File f2=new File(dstDir +"/" + sdf.format(d) + "/" + f.getName()); System.out.println("Moving " + f + " to " + f2); f.renameTo(f2); } } }