aspose file tools*
The moose likes Beginning Java and the fly likes delete logfiles that are older than 3 months Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "delete logfiles that are older than 3 months" Watch "delete logfiles that are older than 3 months" New topic
Author

delete logfiles that are older than 3 months

Angela Stempfel
Greenhorn

Joined: Nov 27, 2001
Posts: 15
hi all
how can i check if i file is older than 3 months? i have to dates:
-the date when the logfile was created
- the current date
thanks
angela
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
The lastModified() of File will return a long representing the date last modified. Convert that to a Date and do your check.
Jason Kretzer
Ranch Hand

Joined: May 31, 2001
Posts: 280
To expand a little on the previous post, first set up a constant that would hold the number of miliseconds in the three month period--approximately 90 days. Subtract this number from the current day's date which can be found using System.currentTimeMillis(). If the date of the file( from the lastModified() method of File) is less than the number just calculated above, then delete it; else keep it.
Hope this helps.
-Jason


Jason R. Kretzer<br />Software Engineer<br />System Administrator<br /><a href="http://alia.iwarp.com" target="_blank" rel="nofollow">http://alia.iwarp.com</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: delete logfiles that are older than 3 months