File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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: 24199

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!