AgeFileFilter

29 07 2010

To get the list of files of directory is simple. If we want the list of files depending on the modified date time of the file. This can be achived by using AgeFileFilter from Apache’s commons-io.

Get the list of files which is modified with in 24 hrs:

String files[] = new File("myLocation").list();

will return all files in the folder(myLocation).
To get the recent files we can use AgeFileFilter
private static FileFilter getFileFilter() {
	Calendar cal = Calendar.getInstance();
	cal.add(Calendar.DATE, -1);
	return new AgeFileFilter(cal.getTime(), false);
}

Here AgeFileFilter takes cutoff period and a boolean
boolean false indicates the files created after the given cutoff period and vice versa.
And this FileFilter has to apply for the listFiles of dir
Files files[] = new File("myLocation").listFiles(getFileFilter());

will return the array of files which are been modified with in 24 hrs.


Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s




Follow

Get every new post delivered to your Inbox.