• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

how to delete files datewise..

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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()
 
aslam parveez
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perfect Joanne!
 
Legend has it that if you rub the right tiny ad, a genie comes out.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic