• Post Reply Bookmark Topic Watch Topic
  • New Topic

Display list of files in a directory according to a particular date as input (JAVA+UNIX)  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to write a program, which when executed in PUTTY, asks for month and year as input and displays only the files having their modified(or created) date matching the inputs. for ex- if user enters january 2013, then the output must be the files created or modified in jan'2013. I am trying to use AgeFileFilter but not getting the output for a particular date.

Anybody having a solution ?
 
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well AgeFileFilter is not a class in the standard API so most people here probably won't know how to use it. Why don't you show us the code and give us some examples of the output you are actually getting compared with what you were expecting.
 
Surya Sharma
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having problems with the code, not able to get the exact thing.
I was looking at this code,
http://www.avajava.com/tutorials/lessons/how-do-i-filter-files-based-on-their-last-modified-dates.html

but it displays all files, (at and before) or (at and after) the mentioned date.
But i want that if i provide jan'2013, i should get all the files for jan 2013 leaving the other files.
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Surya Sharma wrote:But i want that if i provide jan'2013, i should get all the files for jan 2013 leaving the other files.

Then AgeFileFilter is the wrong thing to use. As it says
The boolean value specifies whether the returned files should come before or after the cutoff date/time.
So AgeFileFilter is designed to give you files before or after a given date, not ones that match the given date.
You need to either see if the Apache Commons IO library has another filter that matches your needs or write your own. All you need to do is extend the FileFilter class and then override the accept method so that it checks the date of the file and returns true if it matches your date and false otherwise.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!