This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Java in General and the fly likes Deleting old files in directory ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Deleting old files in directory ?" Watch "Deleting old files in directory ?" New topic

Deleting old files in directory ?

Z Zia

Joined: Oct 03, 2004
Posts: 24

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.

Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24195

Use to get a list of the files in a directory, and then just use lastModified() to check the age of each file.

[Jess in Action][AskingGoodQuestions]
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
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...

Co-author of SCMAD Exam Guide, Author of JMADPlus
I agree. Here's the link:
subject: Deleting old files in directory ?
It's not a secret anymore!