Hi,
i'm trying to copy and paste 12 last modified files from a folder to another one.
my code is working but it gets every files in the folder with any dates.
any help will be appreciated.
Thank you very much
import java.io.*;
import java.text.*;
import java.util.*;
class FileFilterDateIntervalUtils implements FilenameFilter {
String dateStart;
String dateEnd;
SimpleDateFormat sdf;
public FileFilterDateIntervalUtils(String dateStart, String dateEnd) {
this.dateStart = dateStart;
this.dateEnd = dateEnd;
sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss a");
}
public boolean accept(File dir, String name) {
Date d = new Date(new File(dir, name).lastModified());
String current = sdf.format(d);
return ((dateStart.compareTo(current) < 0
&& (dateEnd.compareTo(current) >= 0)));
}
}
class FileSortDateInterval
{
public static void main(String[] args)
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss a");
FileFilterDateIntervalUtils filter = new FileFilterDateIntervalUtils("2000-01-17 11:30:00 AM", "3011-12-31 10:30:00 PM");
File folder = new File("C:/Files");
File files[] = folder.listFiles(filter);
for (File f : files) {
System.out.println(f.getName() + " " + sdf.format(new Date(f.lastModified())));
File dir = new File("C:/Last12Files");
boolean success = f.renameTo(new File(dir,f.getName()));
if (!success)
}
}
}