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..
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.
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()