Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Deleting old files in directory ?

 
Z Zia
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have some apps that process files and move them in a backup directory. I wish to delete old files from that directory and automate application; please suggest:

1. How can app delete files after a specific date. Example: I wish to delete all files that are more than 14 days old in a directory?

2. Please share code if somone has already develop this sort of component/ function.

Regards,
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use java.io.File.listFiles() to get a list of the files in a directory, and then just use lastModified() to check the age of each file.
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Z Zia,
The info provided by Mr.Ernest is kinda enough to develop the application that fit your requirements... Could you try to code by yourself and learn things so that your programming skill will be improved? If you get stuck on something, you may ask questions here and we are here to help you...
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic