aspose file tools*
The moose likes Java in General and the fly likes how to delete files datewise.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to delete files datewise.." Watch "how to delete files datewise.." New topic
Author

how to delete files datewise..

unnikuttan kerala
Greenhorn

Joined: Mar 23, 2006
Posts: 7
hello..

this is my first post in this forum.
i am trying to do a server routine check. in linux we have sub directories..am having one directory which stores all the log files of the server. i want to delete the files on 25th of every month. condition is that last 10 days file must be there..that means..delete the files created on 1-15 th of every month...

one idea is get system date ie 25th.then go 10 days behind and delete all the files upto that date..

how to create a java program..for that..
aslam parveez
Ranch Hand

Joined: Apr 25, 2006
Posts: 47
Yes you can get the current date and subtract 10 from it, then going thru the list of files in the specified folder get the lastModified date and if it is before the date that you have captured after subtracting 10 delete that file. Here is a sample code to do the same , i have considered "d:/temp" as the folder from where files are to be deleted.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3169
    
  10
You could also use the listFiles() method that returns an array of File objects - you don't need to create them in the loop then.
And you could also pass a FileFilter or FilenameFilter that only returned files before a given date to the listFiles() method. All you would need to do in your loop then is call File.delete()


Joanne
aslam parveez
Ranch Hand

Joined: Apr 25, 2006
Posts: 47
Perfect Joanne!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to delete files datewise..
 
Similar Threads
Deleting old files in directory ?
The system cannot find the path specified
Deleting a Folder or dir which contain more than 10K subfolders
Delete Files Older than 'n' days
Multiple Date Files Deletion