Use a
FilenameFilter (Java Platform SE 7 )[
^] and pass that to
listFiles()
:
FilenameFilter fileNameFilter = new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
String match = String.format("%02d-%02d-%04d_%02d", day, month, year, hour);
return name.startsWith(match);
}
};
File[] listOfFiles = folder.listFiles(fileNameFilter);
The above will work for hourly and daily files. Weekly files is more complicated and requires for example creating seven day match strings (as array) and comparing against all. Then using the
Calendar (Java Platform SE 7 )[
^] type and incrementing that in the loop is easier than doing the date calulation manually (the Java
Date
type has no add method while the
Calendar
type has).