Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

delete logfiles that are older than 3 months

 
Angela Stempfel
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic