aspose file tools*
The moose likes Beginning Java and the fly likes getting all the files from a directory for latest date,time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "getting all the files from a directory for latest date,time" Watch "getting all the files from a directory for latest date,time" New topic
Author

getting all the files from a directory for latest date,time

Sonal Sharma
Ranch Hand

Joined: May 13, 2006
Posts: 62
I want to read the latest files in a directory by comparing its date and time of last creation or modification.Can somebody suggest a way to do it?
Any code snippet or tutorial will be highly appreciated.Please try to explain in detail.



Thanks and regard
--Sonal
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

File.listFiles is the method, then call the lastModified() method on each File to get the modification date. Please note that the creation date is NOT available.

The comparison is quite easy; check java.utils.Arrays which has a sort method, you'll need to create a Comparator implementation for that which compares on lastModified().


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getting all the files from a directory for latest date,time